excel VBA DO循环

2024-12-25 21:12:23
推荐回答(3个)
回答1:

Public Sub kkkk()
Dim i, j
i = 2
Do
k = 0
For j = 1 To 50
If Cells(i + j, 1) = Cells(i, 1) Then
k = k + 1
End If
Next j
Range("G" & i & ":G" & i + k).Select
Application.CutCopyMode = False
Selection.Copy
Range("H" & i).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
If k > 0 Then
Range("f" & i + 1 & ":j" & i + k).Select
Selection.ClearContents
End If
i = i + k + 1
Loop Until i > 576
End Sub

回答2:

内部的不要省略啊,发出来看才能清楚!
IsEmpty好像是用来判断变量是否初始化吧。
不能用来判断单元格是否为空!楼主可以修改循环条件
do while Cells(i, 1)<>""
已QQ答复!

回答3:

for...next
do.....loop