How does one import a variable from another function into a subroutine

vincecodegreeen

New Member
Joined
Jan 17, 2014
Messages
39
In these lines of code I am adding hyperlinks to cells in a row. It shows my steps recorded but since there are some 4,000 cells I need a macro to do it automagically. The target cells are in sequential worksheets but in each case follow the sane pattern (i.e. P2, H3, X3, D4, etc.). Could I capture this routine for each sheet by the sub for each? If so how?
Range("B2").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!P2", TextToDisplay:="'Max tree base'!P2"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!H3", TextToDisplay:="'Max tree base'!H3"
Range("B4").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!X3", TextToDisplay:="'Max tree base'!X3"
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!D4", TextToDisplay:="'Max tree base'!D4"
Range("B6").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!L4", TextToDisplay:="'Max tree base'!L4"
Range("B7").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!T4", TextToDisplay:="'Max tree base'!T4"
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi and Welcome to MrExcel,

Yes, you could use variables and repeat that pattern for each hyperlink to be created.

If you'll clarify the pattern you are using, I'll suggest some code.

What defines:
The first sheet of with hyperlinks; last sheet with hyperlinks
Pattern of Anchor cells to have hyperlinks added (including first cell and last cell)
Pattern of Hyperlink SubAddresses
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,142
Members
449,363
Latest member
Yap999

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