Determine Current Active Worksheet
Sponsor
Excel Vba Determine Current Active Worksheet [Q] :
I have several microsoft excel worksheets and i just want to know which one is current when Excel is loaded. Excel worksheets are named for each month as such:
Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec.
I was thinking a Case Statement might be best approach, but don’t know how to code this in excel VBA. In each case I want to go to certain excel cell in each worksheet such as:
Jan = A5, Feb = B2, Mar = C11, etc.
Can anyone write example microsoft vba function or code to achieve this?
Excel Vba Determine Current Active Worksheet [A] :
This is best don in the microsoft excel worksheet module. Right_click the Excel Icon on the File MenuBar (excel version 2003), select view code and paste in the code.
Option Explicit
Private Sub Workbook_Open()
Dim sWksName As String
sWksName = ActiveSheet.Name
If sWksName = “Jan” Then
Range(”a5″).Select
ElseIf sWksName = “Feb” Then
Range(”B2″).Select
ElseIf sWksName = “Mar” Then
Range(”C11″).Select
‘ more code here
End If
MsgBox “Activesheet is ” & sWksName & “,” & ” Cell ” & ActiveCell.Address
End Sub
Private Sub Workbook_SheetActivate(ByVal sh As Object)
Dim sWksName As String
sWksName = sh.Name
If sWksName = “Jan” Then
Range(”a5″).Select
ElseIf sWksName = “Feb” Then
Range(”B2″).Select
ElseIf sWksName = “Mar” Then
Range(”C11″).Select
‘ more code here
End If
MsgBox “You have selected ” & sWksName & ” Cell ” & ActiveCell.Address
End Sub
‘You will remove the msgbox or place an apostrophe before the line after testing the excel vba code.
Rate This Tips:
Incoming excel search terms
excel vba active worksheet,vba active worksheet,excel active worksheet,vba current worksheet,active worksheet vba,excel vba current worksheet,excel current worksheet,mss,active worksheet excel,excel vba activeworksheet,active worksheet excel vba,current worksheet vba,excel vba current worksheet name,excel vba get name of active worksheet,vba activeworksheet,activesheet vba,excel vba get current worksheet name,active worksheet in vba,activeworksheet vba,activeworksheet vba excel,current worksheet excel,excel activeworksheet,excel vba active worksheet name,excel vba determine active sheet,excel vba get current worksheet,vba current worksheet name,vba excel active worksheet,vba find name of active worksheet,,active worksheet name vba,activeworksheet excel,determine current sheet vba,excel active worksheet vba,excel vba active sheet,excel vba current sheet,excel vba if activesheet name,get active worksheet in vba,macro to determine active sheet,ms excel determine current sheet name,vba active worksheet name,vba excel activeworksheet,vba get current worksheet,vba select active worksheet,active worksheet,active worksheets vba,activesheet excel 2007 marco options name,assigning activesheet to a variable vba,code for active sheet in excel macro,current worksheet excel vba,current worksheets vba
Related Excel Tips
Comments
One Comment on Determine Current Active Worksheet
-
Nathan Hull on
Sun, 22nd Mar 2009 4:20 pm
Thank you for the kind comments on my blog post about Excel. WoW this blog is chock full of great information. You do an excellent job of helping us out with difficult tasks. Thanks for all the work you put into this. If you get time feel free to stop by my post on Excel Changing Row Hight In Excel 2007.
Have another excel answer or questions for this problem ?
Feel free to post it here..














