Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
ann ann is offline
external usenet poster
 
Posts: 210
Default Help with Macro in selecting sheets.

I have recorded a macro and am experiencing problems because during the
recording of the macro sheet names have been hard coded. As time has
progressed, extra data has been added and extra sheets have been added and
therefore when I run it I get the message €œRun time Error €˜9, Subscript out
of range€. When I select debug it points to the line that starts
Sheets(Array("sheet 1€, €œsheet 2€,€¦.€

I therefore have 2 problems:-

Problem 1.

Sheets("ZZZ ABC").Select
Sheets("ZZZ ABC ").Copy After:=Sheets(67)
Sheets("ZZZ ABC (2)").Select
Sheets("ZZZ ABC (2)").Name = "Total"

How can the above be changed so that rather than selecting sheet called ZZZ
ABC, the very last sheet is selected, copied and then renamed to Total?

Problem 2.

How can the array statement be changed so that it selects all sheets except
TOTAL? rather than as present which looks like:-

Sheets(Array("sheet 1€, €œsheet 2€,€¦.€

Please help, thank you in anticipation.

--
Thank U and Regards

Ann

  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 10,593
Default Help with Macro in selecting sheets.


"Ann" wrote in message
...
I have recorded a macro and am experiencing problems because during the
recording of the macro sheet names have been hard coded. As time has
progressed, extra data has been added and extra sheets have been added and
therefore when I run it I get the message "Run time Error '9', Subscript
out
of range". When I select debug it points to the line that starts
Sheets(Array("sheet 1", "sheet 2",.."

I therefore have 2 problems:-

Problem 1.

Sheets("ZZZ ABC").Select
Sheets("ZZZ ABC ").Copy After:=Sheets(67)
Sheets("ZZZ ABC (2)").Select
Sheets("ZZZ ABC (2)").Name = "Total"

How can the above be changed so that rather than selecting sheet called
ZZZ
ABC, the very last sheet is selected, copied and then renamed to Total?



Worksheets(Worksheets.Count).Copy after:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = "Total"

Problem 2.

How can the array statement be changed so that it selects all sheets
except
TOTAL? rather than as present which looks like:-

Sheets(Array("sheet 1", "sheet 2",.."

Please help, thank you in anticipation.



Dim sSheets As String
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
If sh.Name < "Total" Then
sSheets = sSheets & sh.Name & ","
End If
Next sh
sSheets = Left(sSheets, Len(sSheets) - 1)
Worksheets(Split(sSheets, ",")).Select


  #3   Report Post  
Posted to microsoft.public.excel.newusers
ann ann is offline
external usenet poster
 
Posts: 210
Default Help with Macro in selecting sheets.

Bob,

Thank U very much for you kind assistance, both your solutions worked.

I have one more question, the last part of the macro does the following:-

In sheet TOTAL (which is the last sheet), cells Q2 to V2, insert a formula
to sum cells Q2 to V2 from the first sheet to the last sheet -1 (Total is the
last sheet)

The macro recorder records as :-

Sheets("Total").Select
Range("Q2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(€˜sheet1:sheet69!RC)"
Range("Q2").Select


Then the last 4 lines for r2, s2, t2, u2 and v2.

How can the above be changed so that sheet names sheet1 and sheet69 are not
hard coded?

Your kind assistance will be much appreciated.

--
Thank U and Regards

Ann



"Bob Phillips" wrote:


"Ann" wrote in message
...
I have recorded a macro and am experiencing problems because during the
recording of the macro sheet names have been hard coded. As time has
progressed, extra data has been added and extra sheets have been added and
therefore when I run it I get the message "Run time Error '9', Subscript
out
of range". When I select debug it points to the line that starts
Sheets(Array("sheet 1", "sheet 2",.."

I therefore have 2 problems:-

Problem 1.

Sheets("ZZZ ABC").Select
Sheets("ZZZ ABC ").Copy After:=Sheets(67)
Sheets("ZZZ ABC (2)").Select
Sheets("ZZZ ABC (2)").Name = "Total"

How can the above be changed so that rather than selecting sheet called
ZZZ
ABC, the very last sheet is selected, copied and then renamed to Total?



Worksheets(Worksheets.Count).Copy after:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = "Total"

Problem 2.

How can the array statement be changed so that it selects all sheets
except
TOTAL? rather than as present which looks like:-

Sheets(Array("sheet 1", "sheet 2",.."

Please help, thank you in anticipation.



Dim sSheets As String
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
If sh.Name < "Total" Then
sSheets = sSheets & sh.Name & ","
End If
Next sh
sSheets = Left(sSheets, Len(sSheets) - 1)
Worksheets(Split(sSheets, ",")).Select



  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 10,593
Default Help with Macro in selecting sheets.

Worksheets("Total").Range("Q2").FormulaR1C1 = _
"=SUM('" & Worksheets(1).Name & ":" & _
Worksheets(Worksheets.Count - 1).Name & "'!RC)"


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Ann" wrote in message
...
Bob,

Thank U very much for you kind assistance, both your solutions worked.

I have one more question, the last part of the macro does the following:-

In sheet TOTAL (which is the last sheet), cells Q2 to V2, insert a formula
to sum cells Q2 to V2 from the first sheet to the last sheet -1 (Total is
the
last sheet)

The macro recorder records as :-

Sheets("Total").Select
Range("Q2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM('sheet1:sheet69'!RC)"
Range("Q2").Select


Then the last 4 lines for r2, s2, t2, u2 and v2.

How can the above be changed so that sheet names sheet1 and sheet69 are
not
hard coded?

Your kind assistance will be much appreciated.

--
Thank U and Regards

Ann



"Bob Phillips" wrote:


"Ann" wrote in message
...
I have recorded a macro and am experiencing problems because during the
recording of the macro sheet names have been hard coded. As time has
progressed, extra data has been added and extra sheets have been added
and
therefore when I run it I get the message "Run time Error '9',
Subscript
out
of range". When I select debug it points to the line that starts
Sheets(Array("sheet 1", "sheet 2",.."

I therefore have 2 problems:-

Problem 1.

Sheets("ZZZ ABC").Select
Sheets("ZZZ ABC ").Copy After:=Sheets(67)
Sheets("ZZZ ABC (2)").Select
Sheets("ZZZ ABC (2)").Name = "Total"

How can the above be changed so that rather than selecting sheet called
ZZZ
ABC, the very last sheet is selected, copied and then renamed to Total?



Worksheets(Worksheets.Count).Copy after:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = "Total"

Problem 2.

How can the array statement be changed so that it selects all sheets
except
TOTAL? rather than as present which looks like:-

Sheets(Array("sheet 1", "sheet 2",.."

Please help, thank you in anticipation.



Dim sSheets As String
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
If sh.Name < "Total" Then
sSheets = sSheets & sh.Name & ","
End If
Next sh
sSheets = Left(sSheets, Len(sSheets) - 1)
Worksheets(Split(sSheets, ",")).Select





  #5   Report Post  
Posted to microsoft.public.excel.newusers
ann ann is offline
external usenet poster
 
Posts: 210
Default Help with Macro in selecting sheets.

Bob,

What can i say except THANK YOU VERY MUCH.

I am really gratefull for your kind assistance.

--
Thank U and Regards

Ann



"Bob Phillips" wrote:

Worksheets("Total").Range("Q2").FormulaR1C1 = _
"=SUM('" & Worksheets(1).Name & ":" & _
Worksheets(Worksheets.Count - 1).Name & "'!RC)"


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Ann" wrote in message
...
Bob,

Thank U very much for you kind assistance, both your solutions worked.

I have one more question, the last part of the macro does the following:-

In sheet TOTAL (which is the last sheet), cells Q2 to V2, insert a formula
to sum cells Q2 to V2 from the first sheet to the last sheet -1 (Total is
the
last sheet)

The macro recorder records as :-

Sheets("Total").Select
Range("Q2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM('sheet1:sheet69'!RC)"
Range("Q2").Select


Then the last 4 lines for r2, s2, t2, u2 and v2.

How can the above be changed so that sheet names sheet1 and sheet69 are
not
hard coded?

Your kind assistance will be much appreciated.

--
Thank U and Regards

Ann



"Bob Phillips" wrote:


"Ann" wrote in message
...
I have recorded a macro and am experiencing problems because during the
recording of the macro sheet names have been hard coded. As time has
progressed, extra data has been added and extra sheets have been added
and
therefore when I run it I get the message "Run time Error '9',
Subscript
out
of range". When I select debug it points to the line that starts
Sheets(Array("sheet 1", "sheet 2",.."

I therefore have 2 problems:-

Problem 1.

Sheets("ZZZ ABC").Select
Sheets("ZZZ ABC ").Copy After:=Sheets(67)
Sheets("ZZZ ABC (2)").Select
Sheets("ZZZ ABC (2)").Name = "Total"

How can the above be changed so that rather than selecting sheet called
ZZZ
ABC, the very last sheet is selected, copied and then renamed to Total?


Worksheets(Worksheets.Count).Copy after:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = "Total"

Problem 2.

How can the array statement be changed so that it selects all sheets
except
TOTAL? rather than as present which looks like:-

Sheets(Array("sheet 1", "sheet 2",.."

Please help, thank you in anticipation.


Dim sSheets As String
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
If sh.Name < "Total" Then
sSheets = sSheets & sh.Name & ","
End If
Next sh
sSheets = Left(sSheets, Len(sSheets) - 1)
Worksheets(Split(sSheets, ",")).Select








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
Selecting Multiple Sheets in VBA Gizmo63 Excel Worksheet Functions 4 May 8th 06 01:50 PM
selecting multiple sheets Shaun Excel Worksheet Functions 1 August 31st 05 04:09 PM
Selecting / UnSelecting sheets shuvro_basu Excel Discussion (Misc queries) 1 August 22nd 05 02:09 PM
Selecting sheets - II Dr.Schwartz Excel Discussion (Misc queries) 4 July 25th 05 02:31 PM
Selecting sheets Dr.Schwartz Excel Discussion (Misc queries) 4 July 14th 05 01:49 PM


All times are GMT +1. The time now is 03:27 PM.

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

About Us

"It's about Microsoft Excel"