Solved

Excel 2010 VBA ActiveSheet

Posted on 2014-04-08
5
842 Views
Last Modified: 2014-04-25
Can someone tell me why this does not work and how to fix it?

    If Workbook.ActiveSheet.Active = "Sheet1" Then
        Template_Copy_1
        Create_Name_References_1
    ElseIf Workbook.ActiveSheet.Active = "Sheet2" Then
        Template_Copy_2
        Create_Name_References_2
    ElseIf Workbook.ActiveSheet.Active = "Sheet3" Then
        Template_Copy_3
        Create_Name_References_3
    ElseIf Workbook.ActiveSheet.Active = "Sheet4" Then
        Template_Copy_4
        Create_Name_References_4
    ElseIf Workbook.ActiveSheet.Active = "Sheet5" Then
        Template_Copy_5
        Create_Name_References_5
    End If

Thanks,

B ill
0
Comment
Question by:cowboywm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39987102
    If ActiveSheet.Name= "Sheet1" Then
        Template_Copy_1
        Create_Name_References_1
    ElseIf ActiveSheet.Name = "Sheet2" Then
        Template_Copy_2
        Create_Name_References_2
    ElseIf ActiveSheet.Name = "Sheet3" Then
        Template_Copy_3
        Create_Name_References_3
    ElseIf ActiveSheet.Name = "Sheet4" Then
        Template_Copy_4
        Create_Name_References_4
    ElseIf ActiveSheet.Name = "Sheet5" Then
        Template_Copy_5
        Create_Name_References_5
    End If

Open in new window

0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39987116
You would be better off using a select case structure:
    Select Case ActiveSheet.Name
        Case Is = "Sheet1"
            Template_Copy_1
            Create_Name_References_1
        Case Is = "Sheet2"
            Template_Copy_2
            Create_Name_References_2
        Case Is = "Sheet3"
            Template_Copy_3
            Create_Name_References_3
        Case Is = "Sheet4"
            Template_Copy_4
            Create_Name_References_4
        Case Is = "Sheet5"
            Template_Copy_5
            Create_Name_References_5
    End Select

Open in new window

0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39987839
Didn't I provide an excellent solution. Why did I get a grade B?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Viewers will learn how to find and create templates in Excel 2013.
Viewers will learn the basics of formula auditing in Excel 2013.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question