Solved

Excel 2010 VBA ActiveSheet

Posted on 2014-04-08
5
872 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Viewers will learn the basics of formula auditing in Excel 2013.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

724 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