Solved

Excel 2010 VBA ActiveSheet

Posted on 2014-04-08
5
788 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
5 Comments
 
LVL 26

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 26

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 26

Expert Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Viewers will learn the basics of the new Quick Analysis feature in Excel 2013.
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now