Loop until empty

Pestomania

Board Regular
Joined
May 30, 2018
Messages
105
Hello,

I have a list in column A in an Excel workbook called "Pipe Sizes".

I want workbook "template" to read A2 and assign "job no" to value in A2. Run "start" macro. At end of "start" macro, assign "job no" to value in A3 and run "start" macro.

So on so forth until it hits an empty cell.

How could I do this?
 

sijpie

Well-known Member
Joined
Nov 1, 2008
Messages
3,524
There are several ways to do this. It depends a little bit on how your Start macor is written. If it assumes that it works on the 'Activecell', then you need to select each cell in turn. It will work that way, no problem, but if you have thousands of rows, then selecting each cell will slow down the macro.

A quicker way would then be to pass each cell address to the start macro. If there are only say a hundred rows then in reality the first method is fine. Here goes:

Code:
Sub LoopThroughColA()
    Dim rC As Range
    
    Set rC = Range("A2")         'set to first cell in range
    
    Do While Len(rC)               'do while there are contents in cell
        rC.Select                       'make this cell active
        Start                             'run the start macro
        Set rC = rC.Offset(1, 0)  'set the cell one row down
    Loop
End Sub
 
Last edited:

Forum statistics

Threads
1,078,486
Messages
5,340,616
Members
399,387
Latest member
amrita34

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top