Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code to get the Active worksheet on change of worksheets

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Code to get the Active worksheet on change of worksheets

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

" 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code to get the Active worksheet on change of worksheets

Thanks, that seems to have helped. Now maybe I can get the rest of
it.

On Apr 25, 12:02*pm, Mike H 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



" 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
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
What is the code for the active worksheet? Dr Dan[_2_] Excel Discussion (Misc queries) 12 February 23rd 07 03:12 PM
Code for Returning to Last Active Worksheet Please Don Guillett Excel Programming 2 December 5th 06 06:11 PM
Altering code to reference the worksheet before the active worksheet KimberlyC Excel Programming 8 March 15th 05 10:26 PM
VBA code that only runs when a worksheet is active Paul James[_3_] Excel Programming 4 December 11th 03 01:05 AM
Code to check for active worksheet KimberlyC Excel Programming 2 November 5th 03 02:49 AM


All times are GMT +1. The time now is 07:41 AM.

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"