我在构建do直到循环时遇到麻烦,该循环将使D列从D4开始循环,并一直重复执行Select Case函数,直到遇到空单元格为止。附件是我的代码。如果这是一个多余的问题,我深表歉意,我已经尝试了所有发现的内容,但是它没有起作用,所以我想知道代码中是否还有其他东西弄乱了它。
Sub FindSupervisior()
Dim Position As String
range("D4").Select
Position = ActiveCell
'i need to add a loop around this section to do the entire column until empty
Select Case Position
Case "Woodyard / Pulp E&I"
Position = "Boss A"
Case "Maintenance - Primary Pro"
Position = "Boss B"
End Select
ActiveCell.Offset(, 1).Value = Position
ActiveCell.Offset(1, 0).Activate
End Sub
答案 0 :(得分:3)
在这里Excel VBA - Do Until Blank Cell
,您会发现Scott Craner的答案很有用。或者这是一个简单的例子
Dim i = 4 ' starting row
While Not IsEmpty(Cells(i, 4)) ' column 4 = column D etc
Select Case etc .......
Cells(i,5).Value = Position
i = i + 1
Wend
答案 1 :(得分:0)
尝试将其添加到您的代码中:
t=4
LastRow = Activesheet.Cells(Rows.Count,4).End(xlUp).Row
Do Until t=LastRow
Position = Activesheet.Cells(t,4).Value
‘Your code
t=t+4
Loop