help with macro

Ron99

Active Member
Joined
Feb 10, 2010
Messages
347
Office Version
  1. 2016
Platform
  1. Windows
Hello....

I have two hyperlink created in sheet1, first hyperlink says (sheet2) second hyperlink says (sheet3), when I click on sheet2 hyperlink it takes me to sheet2 the same with hyperlink sheet3.

macro that I need help on is, after clicking sheet2 hyperlink I am on sheet2, when I click sheet1, sheet2 should be hidden. basically when I click on sheet1 whichever sheet after sheet1 should be hidden, but when I click on hyperlink the sheet should be shown.

Regards,
Ron..
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
what you can do is in the workbook events for on open is hide your sheets less sheet1 then when you click your hyperlink add the code to make the sheet visible. Then when you close the book in the before close event make sure the sheets are hidden again. This code goes in the workbook events, so use Alt + F11 then double click on the right where it says thisworkbook, change the first drop down to Workbook.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets(2).Visible = False
Sheets(3).Visible = False
End Sub
Private Sub Workbook_Open()
Sheets(2).Visible = False
Sheets(3).Visible = False
End Sub

On sheet 1 place this code in the worksheet event, so right click the tab and then select view code then change the first drop down to worksheet then the second to Hyperlink

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Sheets(2).Visible = True
Sheets(2)Select

End Sub
 
Upvote 0
Hey thanx Trevor!

I did exactly the same, I am getting an error in this code

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Sheets(2).Visible = True
Sheets(2)Select

End Sub

I am using excel 2007
 
Upvote 0
In the VBA screen are the sheets named as 2 or are they named as something else. So do they show the names as Sheet2(Sheet2)?
 
Upvote 0
Do you have any protections on the sheets? other than that without seeing the workbook I can't help.
 
Upvote 0
I do not have any protection on the sheet,

when I click on hyperlink it takes me to the sheet, which works fine,

but when I click on sheet1, other sheets should hide, which isn't happening

Regards,
Ron...
 
Upvote 0
In sheet1 view the code by right clicking the sheet tab then change the drop down at the top to worksheet then on the right select activate, the code you need is below.

Private Sub Worksheet_Activate()
Sheets(2).Visible = False
Sheets(3).Visible = False
End Sub
 
Upvote 0
HI...we are almost there, sheet works just fine when I click on sheet1, it hides the other sheets, but now when I am clicking the hyperlink, sheet2 or sheet3 it is not opening.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,763
Members
452,940
Latest member
rootytrip

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