帮忙看个简单的代码,谢谢!
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
a = 1
b = 1
c = 2
d = 1
Do While a < 30000
If xlsheet1.Cells(a, b) = "45678 " Then
xlsheet2.Cells(c, d) = xlsheet1.Cells(a, b + 1)
xlsheet2.Cells(c, d + 1) = xlsheet1.Cells(a + 11, b + 1)
xlsheet2.Cells(c, d + 2) = xlsheet1.Cells(a + 11, b + 13)
a = a + 1
c = c + 1
Else
a = a + 1
End If
Loop
怎么每次运行一半的时候就提示出错?有时候是几百行出错,有时候运行上千行才出错?费解啊!
[解决办法]
赋值的时候,当xlsheet1.cells(m,n)为空值时,有可能出错。
[解决办法]
如楼上所说
xlsheet2.Cells(c, d + 1) = iif(isnull(xlsheet1.Cells(a + 11, b + 1)),vbnullstring,xlsheet1.Cells(a + 11, b + 1))