VBA substitute link

jakobt

Active Member
Joined
May 31, 2010
Messages
337
Want to write VBA code for:

If in column B, the cell include: "John" or "Mike"
then in column C:
Column C: includes link to other workbooks.
- The link should be updated with the following substituting:
- October substituted wih November:
and
-Actuals substituted with Forecast

Example of link:
h:/Germany/October/Reporting.xlsx.sheet_actuals!A1
(some of the links can have different names but the same principle for substitution should apply)
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
test in a COPY of your workbook

Code:
Sub SwapLinks()
Dim Cel As Range, addr As String

For Each Cel In Range("C2", Range("C" & Rows.Count).End(xlUp))
    If Cel.Offset(, -1) = "John" Or Cel.Offset(, -1) = "Mike" Then
        On Error Resume Next
            addr = Cel.Hyperlinks(1).Address
        If Err.Number = 0 Then
            addr = Replace(addr, "_actuals!", "_forecast!")
            addr = Replace(addr, "October", "November")
            With Cel.Hyperlinks(1)
                .Address = addr
                .TextToDisplay = addr
            End With
        End If
        On Error GoTo 0
    End If
Next
 
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,931
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top