[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Excel 2010 VBA ActiveSheet

Posted on 2014-04-08
5
Medium Priority
?
959 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
  • 3
3 Comments
 
LVL 28

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 28

Accepted Solution

by:
MacroShadow earned 2000 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 28

Expert Comment

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

873 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