Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I need a macro that will open a worksheet based on the worksheet name in a
cell. I have four worksheets:-COC, BVO, Vehicles and Reports Now on the Main sheet in cell B2 is a formula which based on criteria will vlookup either COC or BVO or Vehicle or Reports. Once the name appears in B2 I want that applicable sheet to be viewed. |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Private Sub Worksheet_Calculate()
On Error GoTo endit Application.EnableEvents = False With Me.Range("B2") If .Value < "" Then Select Case .Value Case "COC" Sheets("COC").Select Case "BVO" Sheets("BVO").Select 'more Cases here End Select End If End With endit: Application.EnableEvents = True End Sub Right-click on the "Main" sheet tab and "View Code". Copy/paste the above into that sheet module. Edit to suit..........add more Cases..........then Alt + q to return to the Excel window. Gord Dibben MS Excel MVP On Thu, 26 Feb 2009 00:33:01 -0800, Sunnyskies wrote: I need a macro that will open a worksheet based on the worksheet name in a cell. I have four worksheets:-COC, BVO, Vehicles and Reports Now on the Main sheet in cell B2 is a formula which based on criteria will vlookup either COC or BVO or Vehicle or Reports. Once the name appears in B2 I want that applicable sheet to be viewed. |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Try something like this:
Sub test() filetoopen = ThisWorkbook.Worksheets("Main").Range("B2") Workbooks.Open Filename:=filetoopen End Sub Make sure that B2 contains full file name e.g. C:\pathname\COC.xls Regards, Stefi €˛Sunnyskies€¯ ezt Ć*rta: I need a macro that will open a worksheet based on the worksheet name in a cell. I have four worksheets:-COC, BVO, Vehicles and Reports Now on the Main sheet in cell B2 is a formula which based on criteria will vlookup either COC or BVO or Vehicle or Reports. Once the name appears in B2 I want that applicable sheet to be viewed. |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Something like this event macro:
Private Sub Worksheet_Calculate() Set b2 = Range("B2") Sheets(b2.Value).Activate End Sub Because it is worksheet code, it is very easy to install and use: 1. right-click the tab name near the bottom of the window 2. select View Code - this brings up a VBE window 3. paste the stuff in and close the VBE window If you save the workbook, the macro will be saved with it. To remove the macro: 1. bring up the VBE windows as above 2. clear the code out 3. close the VBE window To learn more about macros in general, see: http://www.mvps.org/dmcritchie/excel/getstarted.htm To learn more about Event Macros (worksheet code), see: http://www.mvps.org/dmcritchie/excel/event.htm -- Gary''s Student - gsnu200835 "Sunnyskies" wrote: I need a macro that will open a worksheet based on the worksheet name in a cell. I have four worksheets:-COC, BVO, Vehicles and Reports Now on the Main sheet in cell B2 is a formula which based on criteria will vlookup either COC or BVO or Vehicle or Reports. Once the name appears in B2 I want that applicable sheet to be viewed. |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Sorry, now I see that the OP wrote worksheet and not workbook!
Stefi €˛Gary''s Student€¯ ezt Ć*rta: Something like this event macro: Private Sub Worksheet_Calculate() Set b2 = Range("B2") Sheets(b2.Value).Activate End Sub Because it is worksheet code, it is very easy to install and use: 1. right-click the tab name near the bottom of the window 2. select View Code - this brings up a VBE window 3. paste the stuff in and close the VBE window If you save the workbook, the macro will be saved with it. To remove the macro: 1. bring up the VBE windows as above 2. clear the code out 3. close the VBE window To learn more about macros in general, see: http://www.mvps.org/dmcritchie/excel/getstarted.htm To learn more about Event Macros (worksheet code), see: http://www.mvps.org/dmcritchie/excel/event.htm -- Gary''s Student - gsnu200835 "Sunnyskies" wrote: I need a macro that will open a worksheet based on the worksheet name in a cell. I have four worksheets:-COC, BVO, Vehicles and Reports Now on the Main sheet in cell B2 is a formula which based on criteria will vlookup either COC or BVO or Vehicle or Reports. Once the name appears in B2 I want that applicable sheet to be viewed. |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Now why didn't I think of that instead of the Select Case effort I posted?
Maybe because I'm losing it?<g Gord On Thu, 26 Feb 2009 02:12:06 -0800, Gary''s Student wrote: Something like this event macro: Private Sub Worksheet_Calculate() Set b2 = Range("B2") Sheets(b2.Value).Activate End Sub Because it is worksheet code, it is very easy to install and use: 1. right-click the tab name near the bottom of the window 2. select View Code - this brings up a VBE window 3. paste the stuff in and close the VBE window If you save the workbook, the macro will be saved with it. To remove the macro: 1. bring up the VBE windows as above 2. clear the code out 3. close the VBE window To learn more about macros in general, see: http://www.mvps.org/dmcritchie/excel/getstarted.htm To learn more about Event Macros (worksheet code), see: http://www.mvps.org/dmcritchie/excel/event.htm |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to copy a worksheet and rename based upon text entered in 1 | Excel Discussion (Misc queries) | |||
How to remove macro as I open worksheet? | Excel Discussion (Misc queries) | |||
Deactivating a Forms macro button based on a worksheet condition? | Excel Discussion (Misc queries) | |||
Help with a macro to open to a specific worksheet | Excel Worksheet Functions | |||
How do I get my personal macro worksheet to open whenever I open . | Excel Discussion (Misc queries) |