Running a macro for a number of cells

sparkyhp

Board Regular
Joined
Mar 6, 2009
Messages
66
I have a list of things in column lets say A6: A400 (but this could change each time it is run)

What I want to do is select A6 run the macro (which gets the detail, prints) then go on to cell A7 and do the same until it has gone through every cell and comes to the end.

Do I have to have a defined name ????
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
sparkyhp,

If the macro is to run in column A from row 6 to the last row of data in column A, then try:

Code:
Option Explicit
Sub DataLoop()
  Dim LR As Long, Ctr As Long
  Application.ScreenUpdating = False
  LR = Cells(Rows.Count, 1).End(xlUp).Row
  For Ctr = 6 To LR Step 1
    '***** Your code goes here *****


  Next Ctr
  Application.ScreenUpdating = True
End Sub


Have a great day,
Stan
 
Upvote 0
sparkyhp,

Or, for a range name of "Defined_Name".

Code:
Option Explicit
Sub DataLoopDefinedName()
  Dim c As Range
  Application.ScreenUpdating = False

  For Each c In Range("Defined_Name").Cells
    '***** Your code goes here *****


  Next
  Application.ScreenUpdating = True
End Sub


Have a great day,
Stan
 
Upvote 0

Forum statistics

Threads
1,215,438
Messages
6,124,875
Members
449,192
Latest member
MoonDancer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top