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
active worksheet vba,excel vba get name of active worksheet,excel vba active worksheet,vba current worksheet,activesheet vba,vba active worksheet,excel vba activeworksheet,mss,current worksheet vba,excel active worksheet,excel vba if activesheet name,active worksheet excel,activesheet excel 2007 marco options name,assigning activesheet to a variable vba,code for active sheet in excel macro,determine current sheet vba,excel active worksheet vba,excel current sheet vba,excel current worksheet,excel macro determine active worksheet,excel vba active sheet,excel vba check active sheet,excel vba current active sheet,excel vba current worksheet,excel vba msgbox active sheet,how to check active worksheet in vb,microsoft excel vba current worksheet,using if with active worksheet,vb excel checking if active sheet,vba activeworksheet,vba code for determining worksheet name,vba code start message box on active sheet,vba determine current file,vba excel activesheet,,0,active activesheet excel,active sheet in excel in excel,active sheet name vba,active sheet vba,active work sheet excel vba,active worksheet,active worksheet excel vba,active worksheet name vba,active worksheets and vba,active worksheets vba,active worsheet macro excel,activesheet current,activesheet excel,activesheet excel vba
Related Excel Tips
Comments
Have another excel answer or questions for this problem ?
Feel free to post it here..














