Reputation: 21
I'm having trouble building a do until loop that will loop the column D starting at D4 and keep repeating the Select Case function until it comes across an empty cell. Attached is my code. I apologize if this is a redundant question, I've tried everything I've found and it's not working so I'm wondering if something else in code is messing it up.
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
Upvotes: 2
Views: 18649
Reputation:
Try adding this to your code:
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
Upvotes: 0
Reputation: 788
You will find the answer by Scott Craner useful here Excel VBA - Do Until Blank Cell
Alternatively here's a simple example
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
Upvotes: 3