View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
MacGuy MacGuy is offline
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.