Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How do you identify if a worksheet is in the last position in a Macro?

I have this macro I'm working on. It basically cuts ands
pastes certain ranges from one worksheet into another. I
wanted it to do the same ranges for all the other
worksheets (using 'For Each Worksheet in Worksheets') too
so when it goes to select the range in the worksheet to be
copied I wrote 'ActiveWorksheet.Next.Activate'.
It wasn't moving onto the worksheet after when it got
to 'Next Worksheet', so I moved moved the worksheet I
needed to copy into before the next worksheet I wanted to
copy. This works great except when this worksheets ends up
at the end of the workbook I get an error message. I
wanted to write an If worksheet ("blah")is at the end of
the workbook (or has the last index no. or something) 'End
If' Does anyone have any ideas? I didn't want to specify a
particular index number because I want to use the same
Macro for multiple workbooks and they each have a
different number of worksheets.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do you identify if a worksheet is in the last position in a Macro?

Not sure I understand you description, but if you want to write data from
each sheet (except the summary sheet) to the summary sheet, then this would
work.

for each sh in thisworkbook.worksheets
if sh.name < worksheets("Master").Name then
sh.Range("A1:A25").copy _
Destination:=worksheets("Master"). _
Cells(rows.count,1).End(xlup)(2)
end if
Next

--
Regards,
Tom Ogilvy


Natasha wrote in message
...
I have this macro I'm working on. It basically cuts ands
pastes certain ranges from one worksheet into another. I
wanted it to do the same ranges for all the other
worksheets (using 'For Each Worksheet in Worksheets') too
so when it goes to select the range in the worksheet to be
copied I wrote 'ActiveWorksheet.Next.Activate'.
It wasn't moving onto the worksheet after when it got
to 'Next Worksheet', so I moved moved the worksheet I
needed to copy into before the next worksheet I wanted to
copy. This works great except when this worksheets ends up
at the end of the workbook I get an error message. I
wanted to write an If worksheet ("blah")is at the end of
the workbook (or has the last index no. or something) 'End
If' Does anyone have any ideas? I didn't want to specify a
particular index number because I want to use the same
Macro for multiple workbooks and they each have a
different number of worksheets.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do you identify if a worksheet is in the last position in a Macro?

Hi Natasha,
Try the below. See if that helps.

Dim ws As Worksheet
For Each ws In Worksheets
ws.Activate
----put code in here ----
Next ws

HTH's

-----Original Message-----
I have this macro I'm working on. It basically cuts ands
pastes certain ranges from one worksheet into another. I
wanted it to do the same ranges for all the other
worksheets (using 'For Each Worksheet in Worksheets') too
so when it goes to select the range in the worksheet to

be
copied I wrote 'ActiveWorksheet.Next.Activate'.
It wasn't moving onto the worksheet after when it got
to 'Next Worksheet', so I moved moved the worksheet I
needed to copy into before the next worksheet I wanted to
copy. This works great except when this worksheets ends

up
at the end of the workbook I get an error message. I
wanted to write an If worksheet ("blah")is at the end of
the workbook (or has the last index no. or

something) 'End
If' Does anyone have any ideas? I didn't want to specify

a
particular index number because I want to use the same
Macro for multiple workbooks and they each have a
different number of worksheets.
.

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
Add worksheet at end or last position Brent E Excel Discussion (Misc queries) 4 August 18th 08 10:38 PM
Worksheet Tas position fgwiii[_2_] Excel Discussion (Misc queries) 2 April 2nd 08 09:39 PM
Need to identify active worksheet in macro MLK Excel Worksheet Functions 1 March 13th 07 04:29 PM
Position Picture with macro G Setting up and Configuration of Excel 1 November 28th 05 07:25 PM
Set position into a worksheet using vba Ricardo Mercader Charts and Charting in Excel 2 October 22nd 05 07:09 PM


All times are GMT +1. The time now is 12:03 AM.

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"