【发布时间】:2019-06-21 09:45:22
【问题描述】:
我需要优化代码,我想删除 goto by 循环,但我对建议的循环和 VBA 语法有点麻烦!
Dim a As Integer, b As Integer
a = 2
line1: 'Goto line
Workbooks("0-base de données.xlsx").Worksheets(1).Activate
If Cells(a, 1) <> "" Then
b = a
line2: 'Goto line
If Cells(a, 18) = Cells(a + 1, 18) Then
If Cells(a, 23) <> "" And Cells(a, 23) <= Date And Cells(a, 256) = 1 Then
a = a + 1
GoTo line2
Else
line3: 'Goto line
If Cells(a, 18) = Cells(a + 1, 18) Then
a = a + 1
GoTo line3
Else:
a = a + 1
GoTo line1
End If
End If
Else
If Cells(a, 23) <> "" And Cells(a, 23) <= Date And Cells(a, 256) = 1 Then
Workbooks("0-base de données.xlsx").Worksheets(1).Range("1:2").Copy
Workbooks("0-base de données1.xlsx").Worksheets(1).Activate
D = 2
line5: 'Goto line
If Cells(D, 1) <> "" Then
D = D + 1
GoTo line5
End If
Cells(D, 1).Select
ActiveSheet.Paste
Windows("0-base de données.xlsx").Activate
Rows(b & ":" & a).Select
Selection.Delete Shift:=xlUp
a = b
GoTo line1
End If
a = a + 1
GoTo line1
End If
End If
我已经阅读了很多帖子,但我没有找到任何匹配的代码:(
提前致谢
【问题讨论】:
-
需要优化的工作代码属于Code Review,我建议你在那里发布你的问题。