Including tab name in absolute reference

B

Brad

I have lots of spreadsheets that have the same seven tabs in them. How do I
automatically ensure that the correct tab is selected when running a macro
with absolute references? Is there a way to have the macro select the tab
before running the rest of the macro?

Brad

Excel 2002 on XP Pro SP 3
Excel 2007 on Vista 64
 
R

Ryan H

Your post is kinda vague, plus you didn't post any of your current code.
When you say "spreadsheets" do you mean workbooks? And when you say "tabs" I
assume you mean worksheets within the workbook, right? But I think you want
to activate a sheet in a particular workbook before a particular macro is
ran, right? If so, you can use this code below. It sounds to me you need a
loop referencing workbooks and sheets, which would be more efficient. Hope
this helps! If so, let me know, click "YES" below.

Sub YourSub()

Workbooks("Book1.xls").Sheets("Sheet1").Activate

' your code for that worksheet here

Workbooks("Book1.xls").Sheets("Sheet2").Activate

' your code for that worksheet here
'etc

End Sub
 
B

Brad

Joel,

Thank you for your help. It gave me what I was looking for.

I understand the run time issues of the select method; however, editing the
code would take longer the than improvement in run time on most of my
macros. I will keep this in mind on the macros I use more than 25 times,
but typically I write macros for a project to update multiple workbooks
after the project has started. I typically have less than 20 workbooks on
which to run the macro, but want to be sure that I run it on the correct
sheet.

I also run the macro once on the workbooks I use as templates so I don't
need to run the macros in future projects. In other words, most of my
macros are made by using the recorder, edited as needed, and then deleted at
the end of the day. Editing to avoid the select method would not be
efficient for most of my macros, but I will review at the ones I keep long
term.

Thank you again. It was helpful.

Brad

Excel 2002 on XP Pro SP 3
Excel 2007 on Vista 64
 
B

Brad

Joel H,

Thank you for your help. It gave me what I was looking for.

Sorry for the confusion with the terminology. Yes, when I said tab I meant
sheet and when I said spreadsheet I meant workbook. I will try to be
clearer in the future. While looping and including the workbook names would
reduce the number of times I need to run the macros, it would take longer to
code in the looping than to just manually select the workbook and run the
macro 12 to 15 times.

I use Outlook Express to access the discussion group, so I do not see how to
check the "YES" option from here.

Thank you again. It was helpful.

Brad

Excel 2002 on XP Pro SP 3
Excel 2007 on Vista 64
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top