In the sub below the following code gives an error.
With Sheets("Author ranking").Range(Cells(2, LastColumn), Cells(LastRow, LastColumn))
The problem is definetely with this line, because if I specify the Range to Range("D:D") the sub is working.
What is wrong here?
I attached a test Excel sheet with the macro.
Sub Macro1()
Dim LastColumn As Long
Dim LastColumnJ As Long
Dim LastRow As Long
Dim LastRow2 As Long
Dim JAuth2Rw As Long
Dim Auth2Rw As Long
Dim NextRw As Long
Dim JAuthName As String
Dim AuthName As String
Dim strFirstAddress As String
Sheets("J-Author ranking").Select
LastColumn = Sheets("Author ranking").Cells(1, Columns.Count).End(xlToLeft).Column
LastColumnJ = Sheets("J-Author ranking").Cells(1, Columns.Count).End(xlToLeft).Column
LastRow = Sheets("Author ranking").Cells(Rows.Count, LastColumn).End(xlUp).Row
LastRowJ = Sheets("J-Author ranking").Cells(Rows.Count, LastColumnJ).End(xlUp).Row
For JAuth2Rw = 2 To LastRowJ
JAuthName = Sheets("J-Author ranking").Cells(JAuth2Rw, LastColumnJ)
With Sheets("Author ranking").Range(Cells(2, LastColumn), Cells(LastRow, LastColumn))
Set rngFoundCell = .Find(What:=JAuthName, After:=.Cells(1, 1), LookAt:=xlPart)
If Not rngFoundCell Is Nothing Then
strFirstAddress = rngFoundCell.Address
Do
Sheets("J-Author ranking").Hyperlinks.Add Anchor:=Cells(JAuth2Rw, LastColumnJ), Address:="", _
SubAddress:="'Author ranking'!" & rngFoundCell.Address
Set rngFoundCell = .FindNext(rngFoundCell)
Loop While Not rngFoundCell Is Nothing And rngFoundCell.Address <> strFirstAddress
End If
End With
Next JAuth2Rw
End Sub
Bookmarks