Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Modify Macro

I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Modify Macro

Post one of your sets of 15 lines so that we can see what you are up to...
--
HTH...

Jim Thomlinson


"craig" wrote:

I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Modify Macro

Dim ws1 as Worksheet 'Worksheet with Store List
Dim ws2 as Worksheet 'Worksheet with Data
Dim lRow as Long 'Last Row
Dim cnt as Long 'Count
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 to lRow 'Assumes Row 1 is header info
ws2.Range("A1").AutoFilter Field:= 1, Criteria1:= "=" & ws1.Range("A" &
cnt).Value
Next

That's the basics, let me know if you need help finishing it.

Charles

craig wrote:
I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Modify Macro


Jim Thomlinson wrote:
Post one of your sets of 15 lines so that we can see what you are up to...
--
HTH...

Jim Thomlinson


"craig" wrote:

I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.



Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim strControlDate

'strControlDate = InputBox("Please enter control date for dated
files:", "Control Date Entry", "")

Workbooks.Open Filename:="P:\DPR\GBG PHONE LIST\GBG PHONE LIST
TEMPLATE.xls"
Windows("GBG PHONE LIST MACRO.xls").Activate
strControlDate = Worksheets("MACROS").Range("O17").Value
Sheets("PHONE").Select
Selection.AutoFilter Field:=1, Criteria1:="330"
Range("a2:g65000").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Windows("GBG PHONE LIST TEMPLATE.xls").Activate
Sheets("PHONE").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
Sheets("PHONE").Select
ActiveWorkbook.SaveAs Filename:="P:\Club330\" & strControlDate &
".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
ActiveWindow.Close

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Modify Macro

Difficult for me to tell which are variables. Is ws1 'my worksheet
name'

I'm sure that I can play around with it to get it to work.


Die_Another_Day wrote:
Dim ws1 as Worksheet 'Worksheet with Store List
Dim ws2 as Worksheet 'Worksheet with Data
Dim lRow as Long 'Last Row
Dim cnt as Long 'Count
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 to lRow 'Assumes Row 1 is header info
ws2.Range("A1").AutoFilter Field:= 1, Criteria1:= "=" & ws1.Range("A" &
cnt).Value
Next

That's the basics, let me know if you need help finishing it.

Charles

craig wrote:
I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Modify Macro

Give this a try:
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim strControlDate
Dim ws1 As Worksheet 'Worksheet with Store List
Dim ws2 As Worksheet 'Worksheet with Data
Dim wb1 As Workbook 'Template book
Dim lRow As Long 'Last Row
Dim cnt As Long 'Count
Set ws1 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Craigs
Worksheet")
Set ws2 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Phone")
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 To lRow 'Assumes Row 1 is header info
strControlDate = Workbooks("GBG PHONE LIST
MACRO.xls").Worksheets("MACROS").Range("O17").Valu e
Set wb1 = Workbooks.Open(Filename:="P:\DPR\GBG PHONE LIST\GBG
PHONE LIST TEMPLATE.xls")
ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value
ws2.Range("A2:G65000").SpecialCells(xlCellTypeVisi ble).Copy
wb1.Sheets("Phone").Range("A2").PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
wb1.SaveAs Filename:="P:\Club" & ws1.Range("A" & cnt) & "\" &
strControlDate & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
wb1.Close
Application.CutCopyMode = False
Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Charles

craig wrote:
Difficult for me to tell which are variables. Is ws1 'my worksheet
name'

I'm sure that I can play around with it to get it to work.


Die_Another_Day wrote:
Dim ws1 as Worksheet 'Worksheet with Store List
Dim ws2 as Worksheet 'Worksheet with Data
Dim lRow as Long 'Last Row
Dim cnt as Long 'Count
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 to lRow 'Assumes Row 1 is header info
ws2.Range("A1").AutoFilter Field:= 1, Criteria1:= "=" & ws1.Range("A" &
cnt).Value
Next

That's the basics, let me know if you need help finishing it.

Charles

craig wrote:
I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Modify Macro

Received a compile error he

ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value


Die_Another_Day wrote:
Give this a try:
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim strControlDate
Dim ws1 As Worksheet 'Worksheet with Store List
Dim ws2 As Worksheet 'Worksheet with Data
Dim wb1 As Workbook 'Template book
Dim lRow As Long 'Last Row
Dim cnt As Long 'Count
Set ws1 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Craigs
Worksheet")
Set ws2 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Phone")
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 To lRow 'Assumes Row 1 is header info
strControlDate = Workbooks("GBG PHONE LIST
MACRO.xls").Worksheets("MACROS").Range("O17").Valu e
Set wb1 = Workbooks.Open(Filename:="P:\DPR\GBG PHONE LIST\GBG
PHONE LIST TEMPLATE.xls")
ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value
ws2.Range("A2:G65000").SpecialCells(xlCellTypeVisi ble).Copy
wb1.Sheets("Phone").Range("A2").PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
wb1.SaveAs Filename:="P:\Club" & ws1.Range("A" & cnt) & "\" &
strControlDate & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
wb1.Close
Application.CutCopyMode = False
Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Charles

craig wrote:
Difficult for me to tell which are variables. Is ws1 'my worksheet
name'

I'm sure that I can play around with it to get it to work.


Die_Another_Day wrote:
Dim ws1 as Worksheet 'Worksheet with Store List
Dim ws2 as Worksheet 'Worksheet with Data
Dim lRow as Long 'Last Row
Dim cnt as Long 'Count
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 to lRow 'Assumes Row 1 is header info
ws2.Range("A1").AutoFilter Field:= 1, Criteria1:= "=" & ws1.Range("A" &
cnt).Value
Next

That's the basics, let me know if you need help finishing it.

Charles

craig wrote:
I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Modify Macro

Try ws2.Range("A1:G65000").AutoFilter Field:= 1,
Criteria1:=ws1.Range("A" & cnt).Value

Charles

craig wrote:
Received a compile error he

ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value


Die_Another_Day wrote:
Give this a try:
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim strControlDate
Dim ws1 As Worksheet 'Worksheet with Store List
Dim ws2 As Worksheet 'Worksheet with Data
Dim wb1 As Workbook 'Template book
Dim lRow As Long 'Last Row
Dim cnt As Long 'Count
Set ws1 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Craigs
Worksheet")
Set ws2 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Phone")
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 To lRow 'Assumes Row 1 is header info
strControlDate = Workbooks("GBG PHONE LIST
MACRO.xls").Worksheets("MACROS").Range("O17").Valu e
Set wb1 = Workbooks.Open(Filename:="P:\DPR\GBG PHONE LIST\GBG
PHONE LIST TEMPLATE.xls")
ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value
ws2.Range("A2:G65000").SpecialCells(xlCellTypeVisi ble).Copy
wb1.Sheets("Phone").Range("A2").PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
wb1.SaveAs Filename:="P:\Club" & ws1.Range("A" & cnt) & "\" &
strControlDate & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
wb1.Close
Application.CutCopyMode = False
Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Charles

craig wrote:
Difficult for me to tell which are variables. Is ws1 'my worksheet
name'

I'm sure that I can play around with it to get it to work.


Die_Another_Day wrote:
Dim ws1 as Worksheet 'Worksheet with Store List
Dim ws2 as Worksheet 'Worksheet with Data
Dim lRow as Long 'Last Row
Dim cnt as Long 'Count
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 to lRow 'Assumes Row 1 is header info
ws2.Range("A1").AutoFilter Field:= 1, Criteria1:= "=" & ws1.Range("A" &
cnt).Value
Next

That's the basics, let me know if you need help finishing it.

Charles

craig wrote:
I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Modify Macro

Charles,

That works perfect, thank you so much for your help. This should make
my day much less complicated. Do you have any advice on how to learn
this stuff? Books, web sites?


Die_Another_Day wrote:
Try ws2.Range("A1:G65000").AutoFilter Field:= 1,
Criteria1:=ws1.Range("A" & cnt).Value

Charles

craig wrote:
Received a compile error he

ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value


Die_Another_Day wrote:
Give this a try:
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim strControlDate
Dim ws1 As Worksheet 'Worksheet with Store List
Dim ws2 As Worksheet 'Worksheet with Data
Dim wb1 As Workbook 'Template book
Dim lRow As Long 'Last Row
Dim cnt As Long 'Count
Set ws1 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Craigs
Worksheet")
Set ws2 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Phone")
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 To lRow 'Assumes Row 1 is header info
strControlDate = Workbooks("GBG PHONE LIST
MACRO.xls").Worksheets("MACROS").Range("O17").Valu e
Set wb1 = Workbooks.Open(Filename:="P:\DPR\GBG PHONE LIST\GBG
PHONE LIST TEMPLATE.xls")
ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value
ws2.Range("A2:G65000").SpecialCells(xlCellTypeVisi ble).Copy
wb1.Sheets("Phone").Range("A2").PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
wb1.SaveAs Filename:="P:\Club" & ws1.Range("A" & cnt) & "\" &
strControlDate & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
wb1.Close
Application.CutCopyMode = False
Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Charles

craig wrote:
Difficult for me to tell which are variables. Is ws1 'my worksheet
name'

I'm sure that I can play around with it to get it to work.


Die_Another_Day wrote:
Dim ws1 as Worksheet 'Worksheet with Store List
Dim ws2 as Worksheet 'Worksheet with Data
Dim lRow as Long 'Last Row
Dim cnt as Long 'Count
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 to lRow 'Assumes Row 1 is header info
ws2.Range("A1").AutoFilter Field:= 1, Criteria1:= "=" & ws1.Range("A" &
cnt).Value
Next

That's the basics, let me know if you need help finishing it.

Charles

craig wrote:
I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Modify Macro

If you use Google groups, click the about group, then under "Top
Posters" click on Tom Oglivy, go through and read his posts, there is
more information there than you will get out of a book anytime soon.

Charles

craig wrote:
Charles,

That works perfect, thank you so much for your help. This should make
my day much less complicated. Do you have any advice on how to learn
this stuff? Books, web sites?


Die_Another_Day wrote:
Try ws2.Range("A1:G65000").AutoFilter Field:= 1,
Criteria1:=ws1.Range("A" & cnt).Value

Charles

craig wrote:
Received a compile error he

ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value


Die_Another_Day wrote:
Give this a try:
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim strControlDate
Dim ws1 As Worksheet 'Worksheet with Store List
Dim ws2 As Worksheet 'Worksheet with Data
Dim wb1 As Workbook 'Template book
Dim lRow As Long 'Last Row
Dim cnt As Long 'Count
Set ws1 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Craigs
Worksheet")
Set ws2 = Workbooks("GBG PHONE LIST MACRO.xls").Sheets("Phone")
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 To lRow 'Assumes Row 1 is header info
strControlDate = Workbooks("GBG PHONE LIST
MACRO.xls").Worksheets("MACROS").Range("O17").Valu e
Set wb1 = Workbooks.Open(Filename:="P:\DPR\GBG PHONE LIST\GBG
PHONE LIST TEMPLATE.xls")
ws2.AutoFilter Field:=1, Criteria1:=ws1.Range("A" & cnt).Value
ws2.Range("A2:G65000").SpecialCells(xlCellTypeVisi ble).Copy
wb1.Sheets("Phone").Range("A2").PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
wb1.SaveAs Filename:="P:\Club" & ws1.Range("A" & cnt) & "\" &
strControlDate & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
wb1.Close
Application.CutCopyMode = False
Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Charles

craig wrote:
Difficult for me to tell which are variables. Is ws1 'my worksheet
name'

I'm sure that I can play around with it to get it to work.


Die_Another_Day wrote:
Dim ws1 as Worksheet 'Worksheet with Store List
Dim ws2 as Worksheet 'Worksheet with Data
Dim lRow as Long 'Last Row
Dim cnt as Long 'Count
lRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For cnt = 2 to lRow 'Assumes Row 1 is header info
ws2.Range("A1").AutoFilter Field:= 1, Criteria1:= "=" & ws1.Range("A" &
cnt).Value
Next

That's the basics, let me know if you need help finishing it.

Charles

craig wrote:
I an new to Excel macros, and have inherited a macro that needs to be
simplified. The macro filters a worksheet using a store number as the
unique identifier, copies the filtered data, and saves the new
worksheet with a name that includes that store number. The problem is
that the code for each store contains 15 lines, and when we add a new
store we add 15 more lines. I would like to be able to manage a store
list that the macro would call, and loop through the store list.


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
I need to modify my macro ... Dr. Darrell Excel Discussion (Misc queries) 0 February 24th 10 07:21 PM
Modify A Macro carl Excel Worksheet Functions 1 September 27th 07 08:39 PM
Modify a Macro Carl Excel Worksheet Functions 1 October 28th 06 10:32 AM
Modify a macro Philippe Jacquet Excel Programming 0 January 4th 06 08:45 AM
Help to modify macro please Brian Tozer Excel Programming 2 December 28th 03 08:24 PM


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