Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default create loop in macro for a list

Howdy. My current macro generates a report for a salesperson (let's say,
"Smith, John") by going into each worksheet (there are about 6 - some with 2
pivot tables each) and selecting their name from the Pivot Field drop-down
list. What I have been doing is then going into VB and editting my macro
manually by replacing that saleperson's name with the next one (so "Smith,
John" becomes "Doe, Mary") and re-running the macro. So, I run the macro,
edit by replacing the name - until I've run through all 10 names. There's
got to be a better way? Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default create loop in macro for a list

Quick and dirty:

Sub do_nothing()

x = 1
salesName = Cells(x, 1).Value
Do While salesName < ""
salesName = Cells(x, 1).Value
If salesName < "" Then _
MsgBox salesName '### put your code in place of msgbox ###
x = x + 1
Loop

End Sub

Given you have the names in a continuous list in a single column. The
Cells(r,c) is Cells(rowIndex, columnIndex) so x as 1 is row 1 which
increments each loop and colIndex of 1 is column A. There are other ways to
do this but as I said quick and dirty.
HTH...

--
MacGuy


"VAMS" wrote:

Howdy. My current macro generates a report for a salesperson (let's say,
"Smith, John") by going into each worksheet (there are about 6 - some with 2
pivot tables each) and selecting their name from the Pivot Field drop-down
list. What I have been doing is then going into VB and editting my macro
manually by replacing that saleperson's name with the next one (so "Smith,
John" becomes "Doe, Mary") and re-running the macro. So, I run the macro,
edit by replacing the name - until I've run through all 10 names. There's
got to be a better way? Thank you.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default create loop in macro for a list

Thank you. I'm obviously a novice. I hope it's okay that I post a subset of
my current macro, and then follow it with a section of my list file.
Appreciate your help so much.

Sub Q3SalesRpts()
' Q3SalesRpts Macro
' Q3 RSM Reports
' Keyboard Shortcut: Ctrl+Shift+Q
ActiveSheet.PivotTables("PivotTable1").PivotFields ("SP").CurrentPage = _
"Yost, Christopher"
Range("B15").Select
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel,
True
Selection.Copy
Windows("dddddddd.xls").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Columns("B:M").Select
Selection.Columns.AutoFit
Sheets("Cust $").Select
Windows("Item Customer Summary Data 2008 Q3.xls").Activate
Sheets("by customer").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields ("SP").CurrentPage = _
"Yost, Christopher"
Range("D25").Select
'my macro goes on & on€¦
ChDir "S:\Finance\Sales Support\FY08\Q3 FY08\Apr Sales Reports"
ActiveWorkbook.SaveAs Filename:= _
"S:\Finance\Sales Support\FY08\Q3 FY08\May Sales Reports\May 08
Sales - Yost, Christopher.xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub


Than, in a separate file "list.xls", I have the salespeople listed:
Cell A1 Yost, Christopher
Cell A2 Baker, Ann
Cell A3 William, Phil

....and so forth through Cell A11


"MacGuy" wrote:

Quick and dirty:

Sub do_nothing()

x = 1
salesName = Cells(x, 1).Value
Do While salesName < ""
salesName = Cells(x, 1).Value
If salesName < "" Then _
MsgBox salesName '### put your code in place of msgbox ###
x = x + 1
Loop

End Sub

Given you have the names in a continuous list in a single column. The
Cells(r,c) is Cells(rowIndex, columnIndex) so x as 1 is row 1 which
increments each loop and colIndex of 1 is column A. There are other ways to
do this but as I said quick and dirty.
HTH...

--
MacGuy


"VAMS" wrote:

Howdy. My current macro generates a report for a salesperson (let's say,
"Smith, John") by going into each worksheet (there are about 6 - some with 2
pivot tables each) and selecting their name from the Pivot Field drop-down
list. What I have been doing is then going into VB and editting my macro
manually by replacing that saleperson's name with the next one (so "Smith,
John" becomes "Doe, Mary") and re-running the macro. So, I run the macro,
edit by replacing the name - until I've run through all 10 names. There's
got to be a better way? Thank you.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default create loop in macro for a list

There are several options. One is to use a cell on the sheet to enter a name
and then use that range reference in the macro. Frinstance: Instead of
"Smith, John", you would have Range("A1").Value without the outside quote
marks.

Another way is to use the InputBox.

myVar = InputBox("Enter a name", "Salesperson")
Set c = Sheets("Sales").Find(myVar, LookIn:=xlValues)

Since you didn't post your code, only this sample code is provided.

"VAMS" wrote:

Howdy. My current macro generates a report for a salesperson (let's say,
"Smith, John") by going into each worksheet (there are about 6 - some with 2
pivot tables each) and selecting their name from the Pivot Field drop-down
list. What I have been doing is then going into VB and editting my macro
manually by replacing that saleperson's name with the next one (so "Smith,
John" becomes "Doe, Mary") and re-running the macro. So, I run the macro,
edit by replacing the name - until I've run through all 10 names. There's
got to be a better way? Thank you.

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
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
How to Create a macro from drop down list (Validation List) in excel [email protected] Excel Programming 0 October 31st 06 12:42 PM
create a loop macro andresg1975 Excel Programming 1 September 28th 06 09:39 PM
How to create a macro that compares a list to another list Rampa New Users to Excel 1 January 13th 05 01:15 PM
Macro to move, create formulas and loop NewMacro Excel Programming 5 February 2nd 04 10:12 PM


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