VBA too Large

RBone90

New Member
Joined
Apr 20, 2018
Messages
7
So I am new to VBA and I created a hyperlink that will take me to another page if it is selected. It will also tell me which cell was selected (which is important). However, it was way to big and I am stuck. It begins on 162 and goes to 344 and also needs to go from column J to column DD. PLEASE HELP!

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)

'Update cell B2 in TEST sheet based on the origin of hyperlink
If Sh.Name = "Master" Then
If GSourceCell = "J162" Then
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell J-162"
ElseIf GSourceCell = "J163" Then
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell J-163"
ElseIf GSourceCell = "J164" Then
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell J-164"
ElseIf GSourceCell = "J165" Then
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell J-165"
ElseIf GSourceCell = "J166" Then
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell J-166"
ElseIf GSourceCell = "J168" Then
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell J-168"
etc....
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Why not skip all that If stuff and just do something like:

Code:
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell " & GSourceCell

Or if it just has to have the "-" in it:

"Hyperlinked from cell " & Left(CSourceCell,1) & "-" & Mid(GSourceCell,2,100000)
 
Last edited:
Upvote 0
Just concatenate the source cell with your string

Rich (BB code):
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell " & GSourceCell

HTH
 
Upvote 0
this code should do it:

Code:
let1 = Left(GsourceCell, 1)
 If let1 = "J" Then
  num3 = Val(Right(GsourceCell, 3))
  If num3 > 161 And num3 < 344 Then
    Sheets("TEST").Range("B2").Value = "Hyperlinked from cell J-" & num3
  End If
End If
 
Last edited:
Upvote 0
jproffer & welshgasman, this did not work. does it look correct?

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)

'Update cell B2 in TEST sheet based on the origin of hyperlink
Sheets("TEST").Range("B2").Value = "Hyperlinked from cell " & GSourceCell

End Sub
 
Upvote 0
Which column? The B2 column? The GSourceCell "column" could be anything. It's just adding that string variable to your sentence in B2.

If you need B2 to change as the columns move over that could be done...just need to know what you meant by that.
 
Upvote 0
If that is what you're wanting: For instance if GSourceCell = J163 then you want your sentence to be in B2...and if GSourceCell = L344, you want your sentence in B4 then something like this would do it in just a few lines I think.

Code:
Col = Left(GSourceCell, 1)
Cols = Range("A:" & Col).Columns.Count
    Sheets("TEST").Cells(2, Cols - 8).Value = "Hyperlinked from cell " & GSourceCell
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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