Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Macro to open worksheet based on name in cell

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,646
Default Macro to open worksheet based on name in cell

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.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Macro to open worksheet based on name in cell

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.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,646
Default Macro to open worksheet based on name in cell

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.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro to open worksheet based on name in cell

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.




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro to open worksheet based on name in cell

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to copy a worksheet and rename based upon text entered in 1 edeaston Excel Discussion (Misc queries) 5 December 5th 08 05:47 PM
How to remove macro as I open worksheet? Eric Excel Discussion (Misc queries) 2 November 6th 08 01:10 PM
Deactivating a Forms macro button based on a worksheet condition? Ace70 Excel Discussion (Misc queries) 3 June 10th 07 10:31 PM
Help with a macro to open to a specific worksheet EAHRENS Excel Worksheet Functions 0 November 30th 05 08:36 PM
How do I get my personal macro worksheet to open whenever I open . Claudia_R Excel Discussion (Misc queries) 3 December 9th 04 11:59 PM


All times are GMT +1. The time now is 11:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"