excel loop through columns till a blank one and add text

Jonathan Brotto 1,076 Reputation points
2022-01-17T17:01:09.767+00:00

I know with rows in excel I can loop it downwards with an incrementor till I hit a blank cell where I will add my text. But for columns since they use the alphabet what could I do for this?

Microsoft 365 and Office | Development | Other
Developer technologies | Visual Basic for Applications
Developer technologies | VB
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2022-01-17T17:54:06.917+00:00

    Try a loop like this:

    Dim i As Integer
    For i = 1 To 100
        If Cells(7, i).Value = "" Then
            ' empty cell found   '
    
            Cells(7, i).Value = "New value"
    
            Exit For
        End If
    Next i
    

    It finds the empty cell of the first 100 columns, in 7th row.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.