Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default code to select first sheet

I export several sheets from Access to an Excel workbook and run a macro that
formats each of the sheets (bolds and centers titles, sets column widths,
etc.). When the macro is done, it leaves the focus on the last sheet of the
workbook. I want the focus to be on the first sheet. All of the sheets have
names (not just Sheet1, Sheet2), but I don't want to hard-code the sheet name
because it could change.

Sheets("Sheet1").Select does not work. Is there a generic way to refer to
Sheet1 (that has been renamed)?

Thank you,
Judy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default code to select first sheet

Try this
Sheet1.Select

"Judy Ward" wrote:

I export several sheets from Access to an Excel workbook and run a macro that
formats each of the sheets (bolds and centers titles, sets column widths,
etc.). When the macro is done, it leaves the focus on the last sheet of the
workbook. I want the focus to be on the first sheet. All of the sheets have
names (not just Sheet1, Sheet2), but I don't want to hard-code the sheet name
because it could change.

Sheets("Sheet1").Select does not work. Is there a generic way to refer to
Sheet1 (that has been renamed)?

Thank you,
Judy

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default code to select first sheet

sheets(1).select

Maybe...

Judy Ward wrote:

I export several sheets from Access to an Excel workbook and run a macro that
formats each of the sheets (bolds and centers titles, sets column widths,
etc.). When the macro is done, it leaves the focus on the last sheet of the
workbook. I want the focus to be on the first sheet. All of the sheets have
names (not just Sheet1, Sheet2), but I don't want to hard-code the sheet name
because it could change.

Sheets("Sheet1").Select does not work. Is there a generic way to refer to
Sheet1 (that has been renamed)?

Thank you,
Judy


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default code to select first sheet

I don't know what your loop for formatting the sheets looks like. Ahead of
the loop if you are always on the first sheet when you start the macro put in
these lines -
define a variable such as -
Dim SH as string
SH = ActiveSheet.Name

after the loop has finished -
Sheets(SH).select

You could also try Sheet1.Select if that is always the case for the first
sheet. That is independent of the name. You can see that information in the
VBAProject window. ie. Sheet1 (sheetname)


"Judy Ward" wrote:

I export several sheets from Access to an Excel workbook and run a macro that
formats each of the sheets (bolds and centers titles, sets column widths,
etc.). When the macro is done, it leaves the focus on the last sheet of the
workbook. I want the focus to be on the first sheet. All of the sheets have
names (not just Sheet1, Sheet2), but I don't want to hard-code the sheet name
because it could change.

Sheets("Sheet1").Select does not work. Is there a generic way to refer to
Sheet1 (that has been renamed)?

Thank you,
Judy

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default code to select first sheet

Thank you all very much for replying. This solves my problem.

"Dave Peterson" wrote:

sheets(1).select

Maybe...

Judy Ward wrote:

I export several sheets from Access to an Excel workbook and run a macro that
formats each of the sheets (bolds and centers titles, sets column widths,
etc.). When the macro is done, it leaves the focus on the last sheet of the
workbook. I want the focus to be on the first sheet. All of the sheets have
names (not just Sheet1, Sheet2), but I don't want to hard-code the sheet name
because it could change.

Sheets("Sheet1").Select does not work. Is there a generic way to refer to
Sheet1 (that has been renamed)?

Thank you,
Judy


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default code to select first sheet

Mike,

That will only work if the codename for that sheet has not been changed.

Barb

"Mike" wrote:

Try this
Sheet1.Select

"Judy Ward" wrote:

I export several sheets from Access to an Excel workbook and run a macro that
formats each of the sheets (bolds and centers titles, sets column widths,
etc.). When the macro is done, it leaves the focus on the last sheet of the
workbook. I want the focus to be on the first sheet. All of the sheets have
names (not just Sheet1, Sheet2), but I don't want to hard-code the sheet name
because it could change.

Sheets("Sheet1").Select does not work. Is there a generic way to refer to
Sheet1 (that has been renamed)?

Thank you,
Judy

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I select price from sheet.b where sheet.a part no = sheet.b Sonny Excel Worksheet Functions 4 April 4th 06 05:08 PM
Select sheet with VB code Dunmarie Excel Discussion (Misc queries) 1 January 12th 05 03:44 PM
how can i select all the cells with same color on a sheet if there are multipale colors by vba code uobt Charts and Charting in Excel 1 December 15th 04 05:27 PM
Select Sheet then Select Range Gee[_2_] Excel Programming 3 May 27th 04 10:10 PM


All times are GMT +1. The time now is 08:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"