1. Change the code to:
Sub foo()
Dim lRowSrc, lRowTgt As Long, lCol As Long
Dim i As Integer
Dim s As String, stHeader As String, stValue As String
Dim c As Range
Application.ScreenUpdating = False
With Sheet1 'change if necessary
lRowTgt = 1
For lRowSrc = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
s = .Cells(lRowSrc, 1).Value
i = InStr(s, "=")
If i > 0 Then
stHeader = Left(s, i - 1)
stValue = Trim(Replace(Replace(Right(s, Len(s) - i), "<", ""), ">", ""))
Set c = .Range("1:1").Find(what:=stHeader, lookat:=xlWhole)
If Not c Is Nothing Then
lCol = c.Column
Else
With .Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)
.Value = stHeader
lCol = .Column
End With
End If
If stHeader = .Cells(1, 2).Value Then lRowTgt = lRowTgt + 1
With .Cells(lRowTgt, lCol)
.Value = stValue
If Left(stValue, 5) = "file:" Or Left(stValue, 5) = "http:" Then
.Hyperlinks.Add anchor:=Range(.Address), Address:=stValue
End If
End With
End If
Next lRowSrc
.UsedRange.Columns.AutoFit
.Columns(1).EntireColumn.Delete
End With
Application.ScreenUpdating = True
End Sub
This will add hyperlink to all cell values which start FILE: or HTTP:
2. You don't need to change anything - the code is written to cater for varying field headers. It will loop through all the data in column A, and search for a matching header in Row 1. If the matching header is in Column B, it starts a new row for the data output. If the filed header doesn't already exist in Row 1, it will be added in a new column.
3. It's probably not the ONLY way, but it's almost certainly the fastest and simplest way.
Bookmarks