PC Review


Reply
Thread Tools Rate Thread

Code to get the Active worksheet on change of worksheets

 
 
dannic06@gmail.com
Guest
Posts: n/a
 
      25th Apr 2008
I am having some difficulty here. It has been some time since I have
done any programming in VB for Excel.

I need to get the name of the worksheet and perform a function if it
is changed to that worksheet.

Basicly I have one worksheet with a column with numerical values and I
need to recalculate another sheet to count the number of occurances
within the first sheet when the first is changed or the sheet is
changed. Which ever is easier.

I do not have a set number of fields so I know I will have to loop
through the column of the first sheet. That's not a problem. The
problem is just starting it off.

I have tried this:

Public MyWorkbook As Workbook

Private Sub MyWorkbook_SheetChange(ByVal Sh As Object, _
ByVal Source As Range)


If Sh.Name = "Totals" Then
Msg "testing"
End If


End Sub

but it doesn't seem to do anything for me when I change sheets.

Help would be greatly appreciated.
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      25th Apr 2008
Hi,

Use a different event. use the 'Activate' event from the sheet you want to
work on and then run your code

Private Sub Worksheet_Activate()
MsgBox ActiveSheet.Name & " is active"
'do something
End Sub

Mike

"(E-Mail Removed)" wrote:

> I am having some difficulty here. It has been some time since I have
> done any programming in VB for Excel.
>
> I need to get the name of the worksheet and perform a function if it
> is changed to that worksheet.
>
> Basicly I have one worksheet with a column with numerical values and I
> need to recalculate another sheet to count the number of occurances
> within the first sheet when the first is changed or the sheet is
> changed. Which ever is easier.
>
> I do not have a set number of fields so I know I will have to loop
> through the column of the first sheet. That's not a problem. The
> problem is just starting it off.
>
> I have tried this:
>
> Public MyWorkbook As Workbook
>
> Private Sub MyWorkbook_SheetChange(ByVal Sh As Object, _
> ByVal Source As Range)
>
>
> If Sh.Name = "Totals" Then
> Msg "testing"
> End If
>
>
> End Sub
>
> but it doesn't seem to do anything for me when I change sheets.
>
> Help would be greatly appreciated.
>

 
Reply With Quote
 
Dannic
Guest
Posts: n/a
 
      7th May 2008
Thanks, that seems to have helped. Now maybe I can get the rest of
it.

On Apr 25, 12:02*pm, Mike H <Mi...@discussions.microsoft.com> wrote:
> Hi,
>
> Use a different event. use the 'Activate' event from the sheet you want to
> work on and then run your code
>
> Private Sub Worksheet_Activate()
> MsgBox ActiveSheet.Name & " is active"
> 'do something
> End Sub
>
> Mike
>
>
>
> "danni...@gmail.com" wrote:
> > I am having some difficulty here. *It has been some time since I have
> > done any programming in VB for Excel.

>
> > I need to get the name of the worksheet and perform a function if it
> > is changed to that worksheet.

>
> > Basicly I have one worksheet with a column with numerical values and I
> > need to recalculate another sheet to count the number of occurances
> > within the first sheet when the first is changed or the sheet is
> > changed. *Which ever is easier.

>
> > I do not have a set number of fields so I know I will have to loop
> > through the column of the first sheet. *That's not a problem. *The
> > problem is just starting it off.

>
> > I have tried this:

>
> > Public MyWorkbook As Workbook

>
> > Private Sub MyWorkbook_SheetChange(ByVal Sh As Object, _
> > * * * * ByVal Source As Range)

>
> > If Sh.Name = "Totals" Then
> > *Msg "testing"
> > End If

>
> > End Sub

>
> > but it doesn't seem to do anything for me when I change sheets.

>
> > Help would be greatly appreciated.- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the code for the active worksheet? =?Utf-8?B?RHIgRGFu?= Microsoft Excel Misc 12 23rd Feb 2007 03:12 PM
Code to hide worksheets based on Active Directory login? Joe Microsoft Excel Discussion 0 21st Feb 2006 03:57 AM
Copy data from 3rd worksheets and pasting to active worksheet KimberlyC Microsoft Excel Programming 4 29th Jun 2005 02:09 AM
Altering code to reference the worksheet before the active worksheet KimberlyC Microsoft Excel Programming 8 15th Mar 2005 10:26 PM
Test to see how many worksheets are open and closing active worksheet Steve Lowe Microsoft Excel Programming 2 25th Mar 2004 08:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:03 PM.