Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Need help with looping through a dynamic range

Windows 2k Pro
Excel 2000

I have four columns that contain the various elements of a road name.

Column A contains PREFIX values
Column B contains NAME values
Column C contains SUFFIX values
Column D contains POST DIRECTIONAL values

All values are Strings and each column begins at Row 2 with the values (Row
1 contains headers)

There may or may not be a value in any particular cell.

The total number of rows can vary depending on which list I am evaluating.

What I'd like to do is loop through the list and concatenate the four values
in each row into a single value and display them Column E. While I'm at it
I might as well store the concatenated values in an array I'll call LIST(i).

I know how to concatenate the separate values into a single value, but the
looping is causing me some headaches. As I see it the trick is to figure
out how many rows there are in total so that I know how to set the loop up.

Would you try to do a For-Next loop or maybe a For Each cell loop? I'm not
asking anybody to do this for me, I'm just looking for a nudge in the right
direction.

Any hints or suggestions greatly appreciated.

-gk-


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Need help with looping through a dynamic range

Something like (untested, off the top of my head):

Dim c As Range
Do While WorksheetFunction.CountA(c.EntireRow) < 0
For Each c In Range("A2:A65536")
'your code
Next
Loop

"TBA" wrote in message
...
Windows 2k Pro
Excel 2000

I have four columns that contain the various elements of a road name.

Column A contains PREFIX values
Column B contains NAME values
Column C contains SUFFIX values
Column D contains POST DIRECTIONAL values

All values are Strings and each column begins at Row 2 with the values

(Row
1 contains headers)

There may or may not be a value in any particular cell.

The total number of rows can vary depending on which list I am evaluating.

What I'd like to do is loop through the list and concatenate the four

values
in each row into a single value and display them Column E. While I'm at

it
I might as well store the concatenated values in an array I'll call

LIST(i).

I know how to concatenate the separate values into a single value, but the
looping is causing me some headaches. As I see it the trick is to figure
out how many rows there are in total so that I know how to set the loop

up.

Would you try to do a For-Next loop or maybe a For Each cell loop? I'm

not
asking anybody to do this for me, I'm just looking for a nudge in the

right
direction.

Any hints or suggestions greatly appreciated.

-gk-




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Need help with looping through a dynamic range

Vasant,

Your suggesion won't work properly if column A is empty in the last row, and
you test c before you set it.

Here's an alternative that addresses both points (I hope <G). As it is only
4 columns I concatenate in one statement. A loop would be better if it were
many more, or an unknown amount.

Dim cLastCol As Long, cLastRow As Long, i As Long
Dim rng As Range, c As Range
Dim oRow As Range

ActiveSheet.UsedRange
With ActiveSheet.Cells.SpecialCells(xlLastCell)
cLastCol = .Column
cLastRow = .Row
End With

Set rng = Range("A2", Cells(cLastRow, "D"))
For Each oRow In rng.Rows
If WorksheetFunction.CountA(oRow) < 0 Then
Cells(oRow.Row, "E") = Cells(oRow.Row, "A") & Cells(oRow.Row,
"B") & _
Cells(oRow.Row, "C") & Cells(oRow.Row,
"D")
End If
Next


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Something like (untested, off the top of my head):

Dim c As Range
Do While WorksheetFunction.CountA(c.EntireRow) < 0
For Each c In Range("A2:A65536")
'your code
Next
Loop

"TBA" wrote in message
...
Windows 2k Pro
Excel 2000

I have four columns that contain the various elements of a road name.

Column A contains PREFIX values
Column B contains NAME values
Column C contains SUFFIX values
Column D contains POST DIRECTIONAL values

All values are Strings and each column begins at Row 2 with the values

(Row
1 contains headers)

There may or may not be a value in any particular cell.

The total number of rows can vary depending on which list I am

evaluating.

What I'd like to do is loop through the list and concatenate the four

values
in each row into a single value and display them Column E. While I'm at

it
I might as well store the concatenated values in an array I'll call

LIST(i).

I know how to concatenate the separate values into a single value, but

the
looping is causing me some headaches. As I see it the trick is to

figure
out how many rows there are in total so that I know how to set the loop

up.

Would you try to do a For-Next loop or maybe a For Each cell loop? I'm

not
asking anybody to do this for me, I'm just looking for a nudge in the

right
direction.

Any hints or suggestions greatly appreciated.

-gk-






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Need help with looping through a dynamic range

Hi Bob:

"Bob Phillips" ... wrote ...
Your suggesion won't work properly if column A is empty in the last row,

and
you test c before you set it.<<

"Vasant Nanavati" ... wrote ...
(untested, off the top of my head)<<


Why do you think I put in so many disclaimers in there? <vbg

--

Vasant


"Bob Phillips" wrote in message
...
Vasant,

Your suggesion won't work properly if column A is empty in the last row,

and
you test c before you set it.

Here's an alternative that addresses both points (I hope <G). As it is

only
4 columns I concatenate in one statement. A loop would be better if it

were
many more, or an unknown amount.

Dim cLastCol As Long, cLastRow As Long, i As Long
Dim rng As Range, c As Range
Dim oRow As Range

ActiveSheet.UsedRange
With ActiveSheet.Cells.SpecialCells(xlLastCell)
cLastCol = .Column
cLastRow = .Row
End With

Set rng = Range("A2", Cells(cLastRow, "D"))
For Each oRow In rng.Rows
If WorksheetFunction.CountA(oRow) < 0 Then
Cells(oRow.Row, "E") = Cells(oRow.Row, "A") & Cells(oRow.Row,
"B") & _
Cells(oRow.Row, "C") & Cells(oRow.Row,
"D")
End If
Next


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Something like (untested, off the top of my head):

Dim c As Range
Do While WorksheetFunction.CountA(c.EntireRow) < 0
For Each c In Range("A2:A65536")
'your code
Next
Loop

"TBA" wrote in message
...
Windows 2k Pro
Excel 2000

I have four columns that contain the various elements of a road name.

Column A contains PREFIX values
Column B contains NAME values
Column C contains SUFFIX values
Column D contains POST DIRECTIONAL values

All values are Strings and each column begins at Row 2 with the values

(Row
1 contains headers)

There may or may not be a value in any particular cell.

The total number of rows can vary depending on which list I am

evaluating.

What I'd like to do is loop through the list and concatenate the four

values
in each row into a single value and display them Column E. While I'm

at
it
I might as well store the concatenated values in an array I'll call

LIST(i).

I know how to concatenate the separate values into a single value, but

the
looping is causing me some headaches. As I see it the trick is to

figure
out how many rows there are in total so that I know how to set the

loop
up.

Would you try to do a For-Next loop or maybe a For Each cell loop?

I'm
not
asking anybody to do this for me, I'm just looking for a nudge in the

right
direction.

Any hints or suggestions greatly appreciated.

-gk-








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
Looping thru a range of cells COBOL Dinosaur New Users to Excel 9 June 2nd 07 03:41 AM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
looping across columns in range? Amy Excel Discussion (Misc queries) 3 July 19th 05 08:01 PM
looping through a range Jo[_6_] Excel Programming 1 October 21st 03 11:11 PM
looping cells though a named range Jo[_4_] Excel Programming 1 August 20th 03 12:32 AM


All times are GMT +1. The time now is 11:32 AM.

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

About Us

"It's about Microsoft Excel"