Looping - columns

crisstyd

New Member
Joined
Oct 31, 2007
Messages
12
I'm trying to loop through columns and have gotten stuck. The macro works, but only on Column A and I need it to do the same thing to 5 rows. Basically, this is what I need to do:

Range("a8").Select
(do something special with this data)
Range("a9").Select
(do something special with this data)

Range("a10").Select
(do the same thing to all the cells through cell A371 )

Here is where I am stuck... I need it to move on to "b8" and do the same thing, then on to "c8" or until there is no data in row 8.

I hope this makes sense. I greatly appreciate any help!!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

puru.sve

Active Member
Joined
Apr 29, 2010
Messages
292
Hi Cris

Try to use do while with cells object. like as

Code:
Sub YourProgram()
  i = 1   ' set i equl to 1 to start from column A
  Do While (Cells(8, i).Value <> "")  ' where i will be your counter for column till nonblank 
  Cells(8, i).select ' then do your work 
  Cells(9, i).select ' then do your work 
  Cells(10, i).select ' then do your work 

i = i + 1
Loop
 
 
End Sub
 
Last edited:
Upvote 0

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
5,129
Hi crisstyd,

Try this:

Code:
Option Explicit
Sub Macro6()

    Dim rngCell As Range, _
        rngMyRange As Range
        
    Set rngMyRange = Range("A8:E371") 'Range to work with. Change to suit.
        
    For Each rngCell In rngMyRange
        'crisstyd, this is where your code will go for each cell in the desired range.
    Next rngCell

End Sub

HTH

Robert
 
Upvote 0

crisstyd

New Member
Joined
Oct 31, 2007
Messages
12
Hi crisstyd,

Try this:

Code:
Option Explicit
Sub Macro6()

    Dim rngCell As Range, _
        rngMyRange As Range
        
    Set rngMyRange = Range("A8:E371") 'Range to work with. Change to suit.
        
    For Each rngCell In rngMyRange
        'crisstyd, this is where your code will go for each cell in the desired range.
    Next rngCell

End Sub

HTH

Robert

Thanks. With your help, I got it working. You are a lifesaver!
 
Upvote 0

Forum statistics

Threads
1,195,597
Messages
6,010,641
Members
441,558
Latest member
lambierules

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
Top