From: Gsurfdude on
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!
From: Bob Phillips on

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

do something with cell
Next cell

--

HTH

Bob

"Gsurfdude" <Gsurfdude(a)discussions.microsoft.com> wrote in message
news:9F6A0431-318E-4B02-BD01-E09C8EF40091(a)microsoft.com...
> 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!


From: Mike H on
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.


"Gsurfdude" wrote:

> 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!
From: Mike H on
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.


"Mike H" wrote:

> 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.
>
>
> "Gsurfdude" wrote:
>
> > 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!
From: Dave Peterson on
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


Gsurfdude wrote:
>
> 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!

--

Dave Peterson