Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default How do I simplify a macro in excel?

I have a very lenghty macro that I created in excel to distribute a large
list of data to other sheets in the workbook based upon assignments denoted
on the sheet containing the data listing. As such, my macro simply repeats
the same commands for each of the "other sheets" that the data is being
distributed to. Is there a way to simplfy macros like this in excel? (i.e.
refer to a separate macro containing the repeated commands or refer to
specific lines in the macro rather than redundency)
--
Erik
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How do I simplify a macro in excel?

Hi Erik,

Try something like:

Dim SH as Worksheet

For Each SH in ActiveWorkbook.Worksheets
' Your common sheet processing code here
'Or, call another macro which holds the common code:
Call MyMacro
Next SH

---
Regards,
Norman



"Erik" wrote in message
...
I have a very lenghty macro that I created in excel to distribute a large
list of data to other sheets in the workbook based upon assignments
denoted
on the sheet containing the data listing. As such, my macro simply
repeats
the same commands for each of the "other sheets" that the data is being
distributed to. Is there a way to simplfy macros like this in excel?
(i.e.
refer to a separate macro containing the repeated commands or refer to
specific lines in the macro rather than redundency)
--
Erik



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default How do I simplify a macro in excel?

Perhaps a loop through the worksheets collection:

For Each sh in Worksheets
Do something neat
Next sh

Mike F
"Erik" wrote in message
...
I have a very lenghty macro that I created in excel to distribute a large
list of data to other sheets in the workbook based upon assignments
denoted
on the sheet containing the data listing. As such, my macro simply
repeats
the same commands for each of the "other sheets" that the data is being
distributed to. Is there a way to simplfy macros like this in excel?
(i.e.
refer to a separate macro containing the repeated commands or refer to
specific lines in the macro rather than redundency)
--
Erik



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default How do I simplify a macro in excel?

Here is a section of the macro:

Sheets("A Brown").Select
Range("A7").Select
ActiveCell.FormulaR1C1 = "=IF(Master!RC8=R1C1,Master!RC, )"
Range("A7").Select
Selection.Copy
Range("A7:H555").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Sort Key1:=Range("H7"), Order1:=xlDescending,
Key2:=Range("A7") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A7:A555").Select
Selection.NumberFormat = "_(* #,##0.000_);_(* (#,##0.000);_(*
""-""???_);_(@_)"
Range("C7:D555").Select
Selection.NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(*
""-""??_);_(@_)"
Range("E7:E555").Select
Selection.NumberFormat = "mm/dd/yy;@"
Range("A7").Select
Sheets("A Ohara").Select
Range("A7").Select
ActiveCell.FormulaR1C1 = "=IF(Master!RC8=R1C1,Master!RC, )"
Range("A7").Select
Selection.Copy
Range("A7:H555").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Sort Key1:=Range("H7"), Order1:=xlDescending,
Key2:=Range("A7") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A7:A555").Select
Selection.NumberFormat = "_(* #,##0.000_);_(* (#,##0.000);_(*
""-""???_);_(@_)"
Range("C7:D555").Select
Selection.NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(*
""-""??_);_(@_)"
Range("E7:E555").Select
Selection.NumberFormat = "mm/dd/yy;@"
Range("A7").Select


As you can see, with the exception of the sheet selection command, all of
the commands from sheet to sheet are identical. I think that a loop would
work, but I am not sure how to incorporate that into the macro (because it
would be a first for me). Do you know how to structure that?

--
Erik


"Mike Fogleman" wrote:

Perhaps a loop through the worksheets collection:

For Each sh in Worksheets
Do something neat
Next sh

Mike F
"Erik" wrote in message
...
I have a very lenghty macro that I created in excel to distribute a large
list of data to other sheets in the workbook based upon assignments
denoted
on the sheet containing the data listing. As such, my macro simply
repeats
the same commands for each of the "other sheets" that the data is being
distributed to. Is there a way to simplfy macros like this in excel?
(i.e.
refer to a separate macro containing the repeated commands or refer to
specific lines in the macro rather than redundency)
--
Erik




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default How do I simplify a macro in excel?

Norman,
I tried your suggestion using a Call command and it seemed to work. I was
not familiar with the command. Thank you for the advice. :)
--
Erik


"Norman Jones" wrote:

Hi Erik,

Try something like:

Dim SH as Worksheet

For Each SH in ActiveWorkbook.Worksheets
' Your common sheet processing code here
'Or, call another macro which holds the common code:
Call MyMacro
Next SH

---
Regards,
Norman



"Erik" wrote in message
...
I have a very lenghty macro that I created in excel to distribute a large
list of data to other sheets in the workbook based upon assignments
denoted
on the sheet containing the data listing. As such, my macro simply
repeats
the same commands for each of the "other sheets" that the data is being
distributed to. Is there a way to simplfy macros like this in excel?
(i.e.
refer to a separate macro containing the repeated commands or refer to
specific lines in the macro rather than redundency)
--
Erik




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
Simplify this macro Sunnyskies Excel Discussion (Misc queries) 4 February 9th 07 12:05 PM
simplify a macro Shooter Excel Worksheet Functions 3 January 31st 07 06:22 PM
Simplify macro to show grid lines Mike K[_4_] Excel Programming 1 October 26th 05 02:07 PM
Simplify a macro Einar Excel Programming 7 August 23rd 05 09:05 AM
looking to simplify a recorded macro with code HM Excel Programming 2 February 10th 04 06:35 PM


All times are GMT +1. The time now is 02:16 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"