做累加的vba代码出错
时间:03-09
整理:3721RD
点击:
如题。
Sub area_count()
Dim i As Integer
Dim wg1 As Integer
Dim n As String
Dim m As Integer
n = "高切换"
m = 0
For i = 1 To 1000
If Sheets(1).Range("E" & i).Value = n And Sheets(1).Range("C" & i) = 1 Then
wg1 = 1
Else
wg1 = 0
End If
m = m + wg1
Next i
Sheets(1).Range("H1").Value = m
End Sub
编译时
If Sheets(1).Range("E" & i).Value = n And Sheets(1).Range("C" & i) = 1 Then
出错
去掉 & i
就能通过编译
Sub area_count()
Dim i As Integer
Dim wg1 As Integer
Dim n As String
Dim m As Integer
n = "高切换"
m = 0
For i = 1 To 1000
If Sheets(1).Range("E" & i).Value = n And Sheets(1).Range("C" & i) = 1 Then
wg1 = 1
Else
wg1 = 0
End If
m = m + wg1
Next i
Sheets(1).Range("H1").Value = m
End Sub
编译时
If Sheets(1).Range("E" & i).Value = n And Sheets(1).Range("C" & i) = 1 Then
出错
去掉 & i
就能通过编译
咦~我在2010版本的excel上面编译没有错啊
If Sheets(1).Range("E" & i).Value = n And Sheets(1).Range("C" & i) = 1 Then
好像是没问题哦。
不行的话,你可以尝试将Range("E" & i).更换成:Cells(i,5) 来表示("E" & i).
Cells(i,3)来表示("c" & i).