Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Loop thru used rows in column

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Loop thru used rows in column


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

do something with cell
Next cell

--

HTH

Bob

"Gsurfdude" wrote in message
...
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!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Loop thru used rows in column

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!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Loop thru used rows in column

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!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loop thru used rows in column

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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Loop thru used rows in column

Where did you want these values returned to... a VB array, a range, a comma
delimited string, somewhere else?

--
Rick (MVP - Excel)


"Gsurfdude" wrote in message
...
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!


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Loop thru used rows in column

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.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Where did you want these values returned to... a VB array, a range, a
comma delimited string, somewhere else?

--
Rick (MVP - Excel)


"Gsurfdude" wrote in message
...
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!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create a loop to merge contents of rows 1-4 across column Helmut Excel Programming 2 November 3rd 06 09:11 PM
loop thru column and highlight the rows mariasa Excel Discussion (Misc queries) 1 July 1st 06 08:53 AM
Loop every 26 rows and if.. Robert Excel Programming 4 March 30th 06 10:52 AM
Loop through column headers to search from column name and get cell range Pie Excel Programming 9 December 29th 05 12:17 AM
Cannot loop through rows in C# Howard Excel Programming 2 February 5th 04 03:39 PM


All times are GMT +1. The time now is 07:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"