Loop thru used rows in column

  • Thread starter Thread starter Gsurfdude
  • Start date Start date
G

Gsurfdude

Hello,

I am fairly new to Excel VBA and I need to know how to loop through used
rows in a one column. In logic

for each row in column A starting @ A4 to A whatever

So I need to return values in A4-A whatever is used. I hope that makes sense

Thanks!
 
For Each cell in Range(Range("A4"), Range("A4").End(xlDown))

do something with cell
Next cell
 
Hi,

Try this

Sub marine()
Dim LastCol as Long
lastcol = ActiveSheet.Cells(4, Columns.Count).End(xlToLeft).Column
Set myrange = Range(Cells(4, 1), Cells(4, lastcol))
For Each c In myrange

'Do Things

Next
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
Ignore my post I read it as last used column in a row
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
I like to start at the bottom and look up to find that last used cell. It's
useful if the range could contain empty cells.



Dim myRng as range
dim myCell as range

with worksheets("Somesheetnamehere")
set myrng = .range("A4", .cells(.rows.count,"A").end(xlup))
end with

for each mycell in myrng.cells
msgbox mycell.address 'or whatever you want to do
next mycell
 
Where did you want these values returned to... a VB array, a range, a comma
delimited string, somewhere else?
 
Oh, and when you say "values"... do you mean numbers or text? If text, will
there ever be spaces in the text? I ask this because if the answer is either
"numbers" or "text without spaces", then I think there is a more efficient
way to get to the values than looping through the cells.
 
Back
Top