Select correct sheet when selecting cell

Morre

New Member
Joined
Apr 13, 2011
Messages
15
Hi

I have 52 week sheets in my workbook that are hidden. When a user doubble clicks on a cell the sheet of the current week should be displayed

thnx
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,

Try this (if you double click on cell A1 then show the sheet of todays week number):

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Target.Count > 1 Then Exit Sub
        If Not Intersect(Target, Range("A1")) Is Nothing Then
            weekNum = Trim(Str(Int(((Date - DateSerial(Year(Date), 1, 0)) + 6) / 7)))
            Sheets(weekNum).Visible = True
            Sheets(weekNum).Select
        End If
End Sub
 
Upvote 0
where do i have to place this code? is it in a macro or in a sheet or in the workbook?

hope it works thnx
 
Upvote 0
Hi,

Press Alt+F11 on your main sheet, double click on the sheet in the Project Explorer on the left, paste it in and Bob's your mothers brother.
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,632
Members
452,933
Latest member
patv

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