我一直遇到让我的代码运行其条件循环并停止的问题。这就是我所拥有的:
useWorkaroundToAvoidCrash
我尝试做的是让程序检查一个单元格是否为空,如果另一个单元格没有错误,如果满足该条件,那么程序会复制某一行并将其重新粘贴为它的值,因为该行中的某些单元格是公式。出于某种原因,循环没有退出而Excel崩溃了,我错过了什么吗?
答案 0 :(得分:3)
i = 2应该在
之外Dim i As Integer
i = 2
Do While True
If Cells(i, 1).Value <> "" And Not IsError(Cells(i, 2).Value) Then
Range(Cells(i, 1), Cells(i, 22)).Copy
Range(Cells(i, 1), Cells(i, 22)).PasteSpecial
i = i + 1
Else
Exit Do
End If
Loop
答案 1 :(得分:0)
两点:
Dim i As Integer,Dataset As Variant
i = 2
Do While True
If Cells(i, 1).Value <> "" And Not IsError(Cells(i, 2).Value) Then
'This seems silly, but it overwrites the cell with its value.
Dataset = Range(Cells(i, 1), Cells(i, 22)).Value
Range(Cells(i, 1), Cells(i, 22)).Value = Dataset
i = i + 1
Else
Exit Do
End If
Loop