PC Review


Reply
Thread Tools Rate Thread

code to select first sheet

 
 
=?Utf-8?B?SnVkeSBXYXJk?=
Guest
Posts: n/a
 
      13th Apr 2007
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 With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      13th Apr 2007
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 With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Apr 2007
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
 
Reply With Quote
 
=?Utf-8?B?UmljaCBK?=
Guest
Posts: n/a
 
      13th Apr 2007
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

 
Reply With Quote
 
=?Utf-8?B?SnVkeSBXYXJk?=
Guest
Posts: n/a
 
      13th Apr 2007
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
>

 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      13th Apr 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: vba code to select sheet without a name Shane Devenshire Microsoft Excel Worksheet Functions 2 1st Sep 2009 01:19 PM
Re: vba code to select sheet without a name Don Guillett Microsoft Excel Worksheet Functions 0 31st Aug 2009 02:41 PM
Re: vba code to select sheet without a name Dave Peterson Microsoft Excel Worksheet Functions 0 31st Aug 2009 01:32 PM
How do I select the 2nd sheet from the Right in this code Q Sean Microsoft Excel Programming 9 27th Aug 2007 11:18 AM
Code to Select First Sheet?? Don Microsoft Excel Worksheet Functions 3 14th Sep 2004 05:34 PM


Features
 

Advertising
 

Newsgroups
 


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