VBA batch change single character in tooltip string

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

Column L10:L49 contains a list of hyperlinks with tooltips.

The tooltips contain the following text string:

Go to Training 1981-1997 G1615

The 4 digits at the end are variable but the rest of the text is fixed.

I'd be grateful for some code I can run that will change the tooltip text so the G before the 4 digits is changed to an F.

Many thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Something like this?

VBA Code:
Sub EditScreenTip()
  Dim Cel As Range
  Dim Astr As String
  Dim X As Long
  
  For Each Cel In Selection
    On Error Resume Next
    Astr = Cel.Hyperlinks(1).ScreenTip
    If Astr <> "" Then
      For X = Len(Astr) To 1 Step -1
        If Mid(Astr, X, 1) = "G" Then
          Astr = Left(Astr, X - 1) & "F" & Mid(Astr, X + 1, 100)
          Cel.Hyperlinks(1).ScreenTip = Astr
          Exit For
        End If
      Next X
    End If
  Next Cel

End Sub
 
Upvote 0
Hi Jeff, thanks for helping me.

The code ran without any errors but it didn't amend any of the screentips - they're all still showing "Go to Training 1981-1997 Gxxxx"
 
Upvote 0
Did you grab the code quickly. I edited it and posted another minute later.
 
Upvote 0
Hmmm, it worked for me. Try this code. All errors were being suppressed. Are those cells locked?


VBA Code:
Sub EditScreenTip()
  Dim Cel As Range
  Dim Astr As String
  Dim X As Long
  
  For Each Cel In Selection
    On Error Resume Next
    Astr = Cel.Hyperlinks(1).ScreenTip
         On Error Goto 0
    If Astr <> "" Then
      For X = Len(Astr) To 1 Step -1
        If Mid(Astr, X, 1) = "G" Then
          Astr = Left(Astr, X - 1) & "F" & Mid(Astr, X + 1, 100)
          Cel.Hyperlinks(1).ScreenTip = Astr
          Exit For
        End If
      Next X
    End If
  Next Cel

End Sub
 
Upvote 0
Solution
Aha, yes, the cells were locked and when I unchecked the boxes it works, that's brilliant, thanks a lot Jeff!

As a side point, I didn't know the cells were locked until I checked as I hadn't consciously locked them - I checked a load of random cells and the 'locked' box is checked - I guess that's the default?
 
Upvote 0

Forum statistics

Threads
1,215,606
Messages
6,125,814
Members
449,262
Latest member
hideto94

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