Michael
I've been looking at this and I've come up with this which is very much a work in progress.
Sub GetURLs()
Dim rng As Range
Dim strBaseURL As String
Dim strSection As String
Dim strFileName As String
Dim I As Long
strBaseURL = "\\arkansaselectric.com\FileShares\UserShares\MLittleton\Bailey Pipe Hangers\BAILEY PIPE HANGER DETAILS\"
With Worksheets("Hot Reheat MS")
For I = 5 To .Range("A" & Rows.Count).End(xlUp).Row
If .Range("A" & I).MergeArea.Address = .Range("A" & I).Address Then
If .Range("A" & I).Value <> "" Then
strFileName = Split(.Range("A" & I).Value, "-")(1) & ".pdf"
.Range("B" & I).Value = strSection & "\" & strFileName
End If
Else
If .Range("A" & I).Interior.ColorIndex <> -4142 Then
strSection = Trim(Replace(.Range("A" & I).MergeArea.Cells(1, 1).Value, "Piping System", ""))
End If
End If
Next I
End With
End Sub
It seems to be producing the correct URLs for most sections but there's a problem with the sections in rows 85 to 283 where the header is followed by IsoX.
When that's the case the folder to find the file in is IsoX rather than the section header.
PS I know the code doesn't create hyperlinks, I wanted to make sure of getting the correct URLs before adding a whole bunch of invalid hyperlinks.
Once that's done the code to add the hyperlinks is pretty straightforward.
Actually just realised how it should be possible to ignore the IsoX.
Here's the updated code.
Option Explicit
Sub GetURL()
Dim rng As Range
Dim strBaseURL As String
Dim strSection As String
Dim strFileName As String
Dim I As Long
strBaseURL = "\\arkansaselectric.com\FileShares\UserShares\MLittleton\Bailey Pipe Hangers\BAILEY PIPE HANGER DETAILS\"
With Worksheets("Hot Reheat MS")
For I = 5 To .Range("A" & Rows.Count).End(xlUp).Row
If .Range("A" & I).MergeArea.Address = .Range("A" & I).Address Then
If .Range("A" & I).Value <> "" Then
strFileName = Split(.Range("A" & I).Value, "-")(1) & ".pdf"
.Range("B" & I).Value = strSection & "\" & strFileName
End If
Else
If .Range("A" & I).Interior.ColorIndex <> -4142 Then
If Not .Range("A" & I).Value Like "Iso*" Then
strSection = Trim(Replace(.Range("A" & I).MergeArea.Cells(1, 1).Value, "Piping System", ""))
End If
End If
End If
Next I
End With
End Sub
Bookmarks