identifying the end of a data column

  • Thread starter Thread starter MJKelly
  • Start date Start date
M

MJKelly

If I want to loop through a column of data, I have usually stated the
range (A1:A10). How do I do this without stating the range, but
instead have the loop run in a given column until the first empty
cell?

kind regadrs,
Matt
 
How about

For each C in Activesheet.usedRange.Columns("A").cells

if C.Value="" Then exit For ' This might be redundant

.... doing whatever to C.Value
Next C
 
I think you meant find the last row of data:

lRow = Range("A65536").End(xlUp).Row
 
One common way is this

Sub stance()
Dim myrnge As Range
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set myrange = Range("A1:A" & lastrow)
For Each c In myrange
'do somthing
Next
End Sub

Or another to loop down Column A

Sub stance1()
x = 1
Do
myvalue = Range("A" & x).Value
'do something
x = x + 1
Loop Until myvalue = ""
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top