ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Macro to Select Worksheet (https://www.excelbanter.com/excel-programming/371951-using-macro-select-worksheet.html)

samothman

Using Macro to Select Worksheet
 
I would like to select a worksheet based on a value in a specific cell, I
have tryed everything I know and am unable to accomplish. Here is the code.

Note: There are 8 different workbooks I am trying to move between and I
have already opened all with a macro command. I am using the workbook Weeky
Setup as my "home". The names of the workbooks change every week.

Sub SelectAIM()
Windows("Weekly Setup.xls").Activate
Dim SelectAIM As Name
Set Name = Worksheets("Sheet1").Range("E2")
Windows(SelectAIM).Activate
End Sub

Worksheet "Weekly Setup.xls" is my "master" workbook.
I want to select the workbook as defined in cell "E2" in Weekly Setup


Mark Driscol[_2_]

Using Macro to Select Worksheet
 
You declare SelectAIM as a Name, but then you never set it to anything
before trying to use it. Also, Name is an undefined variable in your
code below that you set equal to a range.

If you use Option Explicit at the beginning of your code, you will get
error messages when you try to use variables you have not declared, or
which you try to set to an object type that is different from what you
declared.

Having said that, I haven't tested this, but I believe something like
the code below may work for you.

Option Explicit
Sub SelectAIM()
Windows("Weekly Setup.xls").Activate
Dim SelectAIM As Range
Set SelectAIM = Worksheets("Sheet1").Range("E2")
Windows(SelectAIM.Value).Activate
End Sub


Mark


samothman wrote:
I would like to select a worksheet based on a value in a specific cell, I
have tryed everything I know and am unable to accomplish. Here is the code.

Note: There are 8 different workbooks I am trying to move between and I
have already opened all with a macro command. I am using the workbook Weeky
Setup as my "home". The names of the workbooks change every week.

Sub SelectAIM()
Windows("Weekly Setup.xls").Activate
Dim SelectAIM As Name
Set Name = Worksheets("Sheet1").Range("E2")
Windows(SelectAIM).Activate
End Sub

Worksheet "Weekly Setup.xls" is my "master" workbook.
I want to select the workbook as defined in cell "E2" in Weekly Setup




All times are GMT +1. The time now is 01:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com