Private Sub CommandButton2_Click()
Dim i As Integer
Dim j As Integer
Dim sh1, sh2
Set sh1 = Worksheets(2)
Set sh2 = Worksheets(3)
For i = 2 To 6
sh2.Cells(2, i) = ""
sh2.Cells(3, i) = ""
sh2.Cells(4, i) = ""
Next
'每次统计前清空各栏数据
For i = 2 To sh1.UsedRange.Rows.Count
If sh1.Cells(i, 22) = "A镇" Then '若乡镇相符则分乡镇统计各税种的合计数
If sh1.Cells(i, 9) = "企业所得税" Or sh1.Cells(i, 9) = "个人所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "价格调节基金" Then sh2.Cells(2, 5) = sh2.Cells(2, 5) + val(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "地方教育附加" Then sh2.Cells(2, 4) = sh2.Cells(2, 4) + val(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "排污费" Then sh2.Cells(2, 6) = sh2.Cells(2, 6) + val(sh1.Cells(i, 8))
Else: sh2.Cells(2, 3) = sh2.Cells(2, 3) + val(sh1.Cells(i, 8))
End If
Next
End Sub这样统计出来的数据与手动统计的数据有一定的差距,而且If sh1.Cells(i, 9) = "企业所得税" Or sh1.Cells(i, 9) = "个人所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8))
这句统计的数据正确,若用If sh1.Cells(i, 9) = "企业所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8)) ElseIf If sh1.Cells(i, 9) = "个人所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8))这样的话,数据就不正常了,求大鸟们说下那儿出了问题???注:这个EXCEL文件我不会上传,那位说下怎么传到这个贴子上来???
Dim i As Integer
Dim j As Integer
Dim sh1, sh2
Set sh1 = Worksheets(2)
Set sh2 = Worksheets(3)
For i = 2 To 6
sh2.Cells(2, i) = ""
sh2.Cells(3, i) = ""
sh2.Cells(4, i) = ""
Next
'每次统计前清空各栏数据
For i = 2 To sh1.UsedRange.Rows.Count
If sh1.Cells(i, 22) = "A镇" Then '若乡镇相符则分乡镇统计各税种的合计数
If sh1.Cells(i, 9) = "企业所得税" Or sh1.Cells(i, 9) = "个人所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "价格调节基金" Then sh2.Cells(2, 5) = sh2.Cells(2, 5) + val(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "地方教育附加" Then sh2.Cells(2, 4) = sh2.Cells(2, 4) + val(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "排污费" Then sh2.Cells(2, 6) = sh2.Cells(2, 6) + val(sh1.Cells(i, 8))
Else: sh2.Cells(2, 3) = sh2.Cells(2, 3) + val(sh1.Cells(i, 8))
End If
Next
End Sub这样统计出来的数据与手动统计的数据有一定的差距,而且If sh1.Cells(i, 9) = "企业所得税" Or sh1.Cells(i, 9) = "个人所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8))
这句统计的数据正确,若用If sh1.Cells(i, 9) = "企业所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8)) ElseIf If sh1.Cells(i, 9) = "个人所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8))这样的话,数据就不正常了,求大鸟们说下那儿出了问题???注:这个EXCEL文件我不会上传,那位说下怎么传到这个贴子上来???
解决方案 »
- 为什么这个语句报"Type mismatch"错误?
- 请教各位老大,EXCEL表格的控件是怎么做出来的?
- 请教:VB中的ObjectContext的主要功能是什么?怎么使用,最好给一个这方面的小例子,谢谢。。
- DBGRID中的布尔字段值的格式化如何做?
- 不知大家有没有测试过,似乎ADO的速度比DAO慢很多!
- 100分的问题
- 求教!
- 南京付费小项目
- 高分求助,求教VB高手,很奇葩的代码,很奇葩的报错,这是BUG吗?
- 谁有VB对图像处理的综合例程,包括亮度,透明度,透空图,动画等。。。最好在一个例程中。。
- VB调用水晶报表问题 急啊!
- webbrowser 加载页面 如何等页面加载完成 再做后续过程
咋一看,这程序,还以为会出编译错误呢,但仔细瞧了瞧,明白个中的问题所在了。
出错代码段如下: If sh1.Cells(i, 22) = "A镇" Then '若乡镇相符则分乡镇统计各税种的合计数
If sh1.Cells(i, 9) = "企业所得税" Or sh1.Cells(i, 9) = "个人所得税" Then sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8))
''''''''''''''''''''' 就是些ElseIf,和下面的Else,其实他们对应的If是上面的【 If sh1.Cells(i, 22) = "A镇"】这个条件
'''''''''''''''''''''原因就是上面的那个If语句中,If和Then写在了同一行上,那么就是一个独立的If语句。
ElseIf sh1.Cells(i, 9) = "价格调节基金" Then sh2.Cells(2, 5) = sh2.Cells(2, 5) + val(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "地方教育附加" Then sh2.Cells(2, 4) = sh2.Cells(2, 4) + val(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "排污费" Then sh2.Cells(2, 6) = sh2.Cells(2, 6) + val(sh1.Cells(i, 8))
Else: sh2.Cells(2, 3) = sh2.Cells(2, 3) + val(sh1.Cells(i, 8))
End If
'''''''''''''''''''''''''''''''''改写如下'''''''''''''''''''''''''''''''''''''''''
If sh1.Cells(i, 22) = "A镇" Then '若乡镇相符则分乡镇统计各税种的合计数
If sh1.Cells(i, 9) = "企业所得税" Or sh1.Cells(i, 9) = "个人所得税" Then
sh2.Cells(2, 2) = sh2.Cells(2, 2) + VAL(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "价格调节基金" Then
sh2.Cells(2, 5) = sh2.Cells(2, 5) + val(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "地方教育附加" Then
sh2.Cells(2, 4) = sh2.Cells(2, 4) + val(sh1.Cells(i, 8))
ElseIf sh1.Cells(i, 9) = "排污费" Then
sh2.Cells(2, 6) = sh2.Cells(2, 6) + val(sh1.Cells(i, 8))
Else
sh2.Cells(2, 3) = sh2.Cells(2, 3) + val(sh1.Cells(i, 8))
End If
End If
Dim i As Integer
Dim j As Integer
Dim sh1, sh2
Set sh1 = Worksheets(2)
Set sh2 = Worksheets(3)
For i = 2 To 6
sh2.Cells(2, i) = ""
sh2.Cells(3, i) = ""
sh2.Cells(4, i) = ""
NextFor i = 2 To sh1.UsedRange.Rows.Count
If sh1.Cells(i, 22) = "A镇" Then
If sh1.Cells(i, 9) = "企业所得税" Or sh1.Cells(i, 9) = "个人所得税" Then
sh2.Cells(2, 2) = sh2.Cells(2, 2) + sh1.Cells(i, 8)
ElseIf sh1.Cells(i, 9) = "价格调节基金" Then
sh2.Cells(2, 5) = sh2.Cells(2, 5) + sh1.Cells(i, 8)
ElseIf sh1.Cells(i, 9) = "地方教育附加" Then
sh2.Cells(2, 4) = sh2.Cells(2, 4) + sh1.Cells(i, 8)
ElseIf sh1.Cells(i, 9) = "排污费" Then
sh2.Cells(2, 6) = sh2.Cells(2, 6) + sh1.Cells(i, 8)
Else
sh2.Cells(2, 3) = sh2.Cells(2, 3) + sh1.Cells(i, 8)
End If
Next
End Sub
总是提示最后一个NEXT没有FOR,怎么回事?
看我上面回复的代码,应该有两个End If的。