I have ColumnB in Excel populated with full pathnames. I want to create a Hyperlink with a [friendly_name] for each ColumnB pathname, in the same row in ColumnC. My hang-up is when reading ColumnB and Offsetting to ColumnC to save the Hyperlink with that cell's Range which is changing with each for/next iteration. I have tried to use a Variant as the ColumnC Range will be changing, but without success. Here is my code thus far.
Sub AddHyperlinkFromPath()
Dim p As Integer 'Iteration number
Dim NumRowsP As Integer 'Row count
Dim myPath As String 'Pathname
Dim myName As String 'File name extracted from myPath
Worksheets("AllFiles").Activate 'Source worksheet
NumRowsP = Range("B8", Range("B8").End(xlDown)).Rows.Count + 7 'Row count
Range("B8").Select 'First full pathname location
For p = 8 To NumRowsP 'Begin at the 8th row to last row
myPath = ActiveCell.Value 'Get pathname
p = 1
myName = Mid(myPath, InStrRev(myPath, "\") + 1, 999) 'Get filename from pathname
ActiveCell.Offset(0, 1).Select 'Moved to Column C
ActiveSheet.Hyperlinks.Add Anchor:=Range("c" & p), Address:=myPath, TextToDisplay:=myName
p = p + 1 'Iterate to next row
ActiveCell.Offset(0, -1).Select 'Move back to Column B
Next
End Sub