kapiva
kapiva

Reputation: 197

Make this code loop until the last non empty row

Everything that I do to incorporate a loop breaks the code.
I tried to use For Loop in iterating through the rows but it errors out on userid line. I just have to do it 20 times, for 20 different rows.

Sub Testbitly()
    Dim userid As String
    Dim apiKey As String
    Dim shortURL As String
    Dim URLcompleto As String

    userid = Sheets("Plan1").Cells(7, 6)
    apiKey = Sheets("Plan1").Cells(7, 7)
    URLcompleto = Sheets("Plan1").Cells(7, 8)

    shortURL = ShortenURL(userid, apiKey, _
        URLcompleto, bitly)
    Range("I7").Select
    ActiveCell.FormulaR1C1 = shortURL
End Sub

Upvotes: 0

Views: 1316

Answers (1)

Vitor
Vitor

Reputation: 11

Sub Testbitly()

 Dim userid As String
 Dim apiKey As String
 Dim shortURL As String
 Dim URLcompleto As String
 Dim LastRow As Long

 LastRow = Sheets("Plan1").Cells(.Rows.Count, "F").End(xlUp).Row

 For i = 7 To LastRow
      userid = Sheets("Plan1").Cells(i, 6)
      apiKey = Sheets("Plan1").Cells(i, 7)
      URLcompleto = Sheets("Plan1").Cells(i, 8)

      shortURL = ShortenURL(userid, apiKey, _
    URLcompleto, bitly)
      Sheets("Plan1").Cells(i, 9).FormulaR1C1 = shortURL
 Next i

End Sub

Upvotes: 1

Related Questions