我有一行代码在调试时完美运行,但在完全执行时一直崩溃。实质上,它应该做的是组合两行数据。我这样做是因为我从数据库导入数据,在该数据库中,它将事务记录在两行中:事务的一侧在一行上,而另一侧在另一行上,前一列的所有数据都是位于这些行中的任何一行上。因此,例如:代码在调试时运行良好,但在完全执行期间崩溃
|trans 1 | 1/1/2015| $500.00| 0 |trans 1 |---------| 0| 497.00|
理想情况下,应该像
|trans 1|1/1/2015|500.00|497.00|
第二排应予删除。
这是我的代码做到这一点:
Sub Collapse_Rows()
Dim ALLCS As Worksheet
Set ALLCS = Sheets("Asset LLC (Input)")
On Error Resume Next
Application.EnableEvents = False
For x = 66515 To 16 Step -1
If ALLCS.Cells(x, 2) = ALLCS.Cells(x + 1, 2) Then
If ALLCS.Cells(x, 28) <> Empty Then
ALLCS.Cells(x + 1, 28) = ALLCS.Cells(x, 28)
End If
End If
If ALLCS.Cells(x - 1, 2) = ALLCS.Cells(x, 2) Then
If ALLCS.Cells(x, 28) <> Empty Then
ALLCS.Cells(x - 1, 28) = ALLCS.Cells(x, 28)
End If
End If
If ALLCS.Cells(x, 5) <> Empty And ALLCS.Cells(x, 2) = Empty Then
ElseIf ALLCS.Cells(x, 24) = Empty Then
ALLCS.Cells(x, 24).EntireRow.Select
Selection.Delete
End If
Next
End Sub
我部分在调试运行这段代码和它工作得很好。当我完全运行代码时,excel崩溃了为什么/如何防止这种情况发生的任何想法?
你应该尝试并添加调试语句(如debug.print)了解此时它崩溃 – Xarylem
究竟会是做什么@Xarylem是 – dom176
ELSEIF在这里纠正 - * ElseIf ALLCS.Cells(x,24)= Empty然后*或它应该是只有在? –