Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Changing the ActiveSheet

I've got a workbook with several different sheets. I want a macro
that will select the required sheet depending on what cell is
highlighted.

For example there are cells for Jan, through to Dec. If the Mar cell
is highlighted, when the user clicks on the macro button I want it to
open the sheet for Mar and do some processing. I know how to do the
processing but how do you change what sheet is active based on this
kind of user action?

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Changing the ActiveSheet

Hi David -

Here's a basic starting point:

Private Sub CommandButton1_Click()
Worksheets(ActiveCell.Value).Activate
End Sub
---
Jay

"David" wrote:

I've got a workbook with several different sheets. I want a macro
that will select the required sheet depending on what cell is
highlighted.

For example there are cells for Jan, through to Dec. If the Mar cell
is highlighted, when the user clicks on the macro button I want it to
open the sheet for Mar and do some processing. I know how to do the
processing but how do you change what sheet is active based on this
kind of user action?

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Changing the ActiveSheet

OK, this works:

sMonth = ActiveCell.Value

Worksheets(sMonth).Activate

Another question, how do I used wildcards in Excel?

For example, if the active cell was "Mar" but the worksheet was Mar
'07, how could I get it to still open the right worksheet?

I tried adding a * after the Worksheets(sMonth) but that didn't work,
any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Changing the ActiveSheet

The following activates the worksheet whose name starts with whatever is in
the activecell (sMonth):

Private Sub CommandButton1_Click()

sMonth = ActiveCell.Value

For Each ws In Worksheets
If InStr(1, ws.Name, sMonth) = 1 Then ws.Activate
Next 'ws

End Sub
---
Jay

"David" wrote:

OK, this works:

sMonth = ActiveCell.Value

Worksheets(sMonth).Activate

Another question, how do I used wildcards in Excel?

For example, if the active cell was "Mar" but the worksheet was Mar
'07, how could I get it to still open the right worksheet?

I tried adding a * after the Worksheets(sMonth) but that didn't work,
any ideas?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Changing the ActiveSheet

Take a look at the LIKE operator.

Mike F
"David" wrote in message
ps.com...
OK, this works:

sMonth = ActiveCell.Value

Worksheets(sMonth).Activate

Another question, how do I used wildcards in Excel?

For example, if the active cell was "Mar" but the worksheet was Mar
'07, how could I get it to still open the right worksheet?

I tried adding a * after the Worksheets(sMonth) but that didn't work,
any ideas?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Changing the ActiveSheet

Thanks for the help so far, it's working well!

Another query.

I have worksheets Apr, May, Jun etc.

Sometimes when I go into Jun worksheet for example, I might need to
also check what was in the previous month, is there an easy way of
doing this rather than saying if it's Jun then check May etc etc? Are
worksheets numbered even though they have names?

Thanks again!


  #7   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Changing the ActiveSheet

Hi David -

Yes, worksheets have an Index property and they are numbered sequentially
from left to right, starting with 1. So, these statements may work for you:

'Check the value in cell A1 of the sheet before the activesheet
MsgBox Worksheets(ActiveSheet.Index - 1).Range("A1")

'Activate the sheet before the activesheet
Worksheets(ActiveSheet.Index - 1).Activate

---
Jay

"David" wrote:

Thanks for the help so far, it's working well!

Another query.

I have worksheets Apr, May, Jun etc.

Sometimes when I go into Jun worksheet for example, I might need to
also check what was in the previous month, is there an easy way of
doing this rather than saying if it's Jun then check May etc etc? Are
worksheets numbered even though they have names?

Thanks again!



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
Copying new activesheet after other activesheet is hidden? Simon Lloyd[_790_] Excel Programming 1 June 20th 06 10:02 AM
activesheet Jim at Eagle Excel Programming 1 April 6th 05 12:21 AM
Get ActiveSheet name in VB Geoff Lambert[_2_] Excel Programming 1 October 8th 04 02:25 PM
ActiveSheet Graham[_3_] Excel Programming 0 July 30th 03 09:08 AM
ActiveSheet Graham[_3_] Excel Programming 0 July 29th 03 04:47 PM


All times are GMT +1. The time now is 04:35 AM.

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

About Us

"It's about Microsoft Excel"