Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel 2010 VBA ActiveSheet

Posted on 2014-04-08
5
Medium Priority
?
945 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 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 27

Expert Comment

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
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)…
Video by: Zack
Viewers will learn the basics of using Excel Tables, the benefits found with them, and some pitfalls.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

618 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