Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Looping thorough records

I have the following code that loops through the records and does fine but I
cannot get it to loop back through all of the records in column A. It looks
at cell A1 and does the loop and stops. What am I doing wrong?

Option Base 1
Public RelOpts() As String
Sub GetRelOpt()
x = 1
NextRow = 0
StrToMatch = Cells(1 + NextRow, 1).Value

ReDim RelOpts(1 To x)


Do While Cells(1 + NextRow, 1).Value < ""
If Cells(1 + NextRow, 1).Value = StrToMatch Then
RelOpts(x) = Cells(1 + NextRow, 2).Value
x = x + 1
ReDim Preserve RelOpts(x) As String
End If
NextRow = NextRow + 1
Loop
y = 1
Do Until RelOpts(y) = ""
CCString = CCString + RelOpts(y) + " ,"
y = y + 1
Loop
Cells(1, 5).Value = Left(CCString, (Len(CCString) - 2))


End Sub


Deb
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Looping thorough records

Are you comparing Cell "A1" to the rest of the cells in column A or
are you looking for duplicates in column A ?
You could get a start on figuring out the problem by declaring all of your variables.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Debi H"
wrote in message
I have the following code that loops through the records and does fine but I
cannot get it to loop back through all of the records in column A. It looks
at cell A1 and does the loop and stops. What am I doing wrong?

Option Base 1
Public RelOpts() As String
Sub GetRelOpt()
x = 1
NextRow = 0
StrToMatch = Cells(1 + NextRow, 1).Value

ReDim RelOpts(1 To x)


Do While Cells(1 + NextRow, 1).Value < ""
If Cells(1 + NextRow, 1).Value = StrToMatch Then
RelOpts(x) = Cells(1 + NextRow, 2).Value
x = x + 1
ReDim Preserve RelOpts(x) As String
End If
NextRow = NextRow + 1
Loop
y = 1
Do Until RelOpts(y) = ""
CCString = CCString + RelOpts(y) + " ,"
y = y + 1
Loop
Cells(1, 5).Value = Left(CCString, (Len(CCString) - 2))


End Sub


Deb
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Looping thorough records

I have a list of parts in column A that I loop through and if they are the
same I get the data from colunm B that matches all the same values in column
A and insert it into C1.
colA ColB

door 1234
door 1234
door 5555
hood 5555
hood 6666
hood 1234

The output would be

col A Col C
door 1234, 5555
hood 5555,6666,1234


"Jim Cone" wrote:

Are you comparing Cell "A1" to the rest of the cells in column A or
are you looking for duplicates in column A ?
You could get a start on figuring out the problem by declaring all of your variables.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Debi H"
wrote in message
I have the following code that loops through the records and does fine but I
cannot get it to loop back through all of the records in column A. It looks
at cell A1 and does the loop and stops. What am I doing wrong?

Option Base 1
Public RelOpts() As String
Sub GetRelOpt()
x = 1
NextRow = 0
StrToMatch = Cells(1 + NextRow, 1).Value

ReDim RelOpts(1 To x)


Do While Cells(1 + NextRow, 1).Value < ""
If Cells(1 + NextRow, 1).Value = StrToMatch Then
RelOpts(x) = Cells(1 + NextRow, 2).Value
x = x + 1
ReDim Preserve RelOpts(x) As String
End If
NextRow = NextRow + 1
Loop
y = 1
Do Until RelOpts(y) = ""
CCString = CCString + RelOpts(y) + " ,"
y = y + 1
Loop
Cells(1, 5).Value = Left(CCString, (Len(CCString) - 2))


End Sub


Deb

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Looping thorough records

Debi,
Move the "StrToMatch = Cells(1 + NextRow, 1).Value" line down so it is
the first line in the Do loop...

Do While Cells(1 + NextRow, 1).Value < ""
StrToMatch = Cells(1 + NextRow, 1).Value
If Cells(1 + NextRow, 1).Value = StrToMatch Then
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html


"Debi H"
wrote in message
I have a list of parts in column A that I loop through and if they are the
same I get the data from colunm B that matches all the same values in column
A and insert it into C1.

colA ColB
door 1234
door 1234
door 5555
hood 5555
hood 6666
hood 1234

The output would be
col A Col C
door 1234, 5555
hood 5555,6666,1234


"Jim Cone" wrote:
Are you comparing Cell "A1" to the rest of the cells in column A or
are you looking for duplicates in column A ?
You could get a start on figuring out the problem by declaring all of your variables.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Looping thorough records

That got all of column B but put did put the field for column B when column A
changed
col A Col C
door 1234, 5555,5555,6666,1234
hood


There should be the matching records for door and the matching records for
door

col A Col C
door 1234, 5555
hood 5555,6666,1234


Does that make sense?

"Jim Cone" wrote:

Debi,
Move the "StrToMatch = Cells(1 + NextRow, 1).Value" line down so it is
the first line in the Do loop...

Do While Cells(1 + NextRow, 1).Value < ""
StrToMatch = Cells(1 + NextRow, 1).Value
If Cells(1 + NextRow, 1).Value = StrToMatch Then
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html


"Debi H"
wrote in message
I have a list of parts in column A that I loop through and if they are the
same I get the data from colunm B that matches all the same values in column
A and insert it into C1.

colA ColB
door 1234
door 1234
door 5555
hood 5555
hood 6666
hood 1234

The output would be
col A Col C
door 1234, 5555
hood 5555,6666,1234


"Jim Cone" wrote:
Are you comparing Cell "A1" to the rest of the cells in column A or
are you looking for duplicates in column A ?
You could get a start on figuring out the problem by declaring all of your variables.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Looping thorough records

Try playing around with this...
'------------------------
Sub GetRelOpt()
Dim x As Long
Dim NextRow As Long
Dim strToMatch
Dim rngCell As Excel.Range

NextRow = 1
Do While Cells(1 + NextRow, 1).Value < ""
x = 3
Set rngCell = Cells(NextRow, 1)
strToMatch = rngCell.Value
Do While Cells(1 + NextRow, 1).Value = strToMatch
rngCell(1, x).Value = Cells(1 + NextRow, 2).Value
NextRow = NextRow + 1
x = x + 1
Loop
NextRow = NextRow + 1
Loop
End Sub
'-----------
Jim Cone


"Debi H"
wrote in message
That got all of column B but put did put the field for column B when column A
changed
col A Col C
door 1234, 5555,5555,6666,1234
hood


There should be the matching records for door and the matching records for
door

col A Col C
door 1234, 5555
hood 5555,6666,1234


Does that make sense?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Looping thorough records

It still did not work and pick up the hood and put the data in the cell in
the B column that related to the hood. Also it put it in 3 different cells
not one

"Debi H" wrote:

That got all of column B but put did put the field for column B when column A
changed
col A Col C
door 1234, 5555,5555,6666,1234
hood


There should be the matching records for door and the matching records for
door

col A Col C
door 1234, 5555
hood 5555,6666,1234


Does that make sense?

"Jim Cone" wrote:

Debi,
Move the "StrToMatch = Cells(1 + NextRow, 1).Value" line down so it is
the first line in the Do loop...

Do While Cells(1 + NextRow, 1).Value < ""
StrToMatch = Cells(1 + NextRow, 1).Value
If Cells(1 + NextRow, 1).Value = StrToMatch Then
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html


"Debi H"
wrote in message
I have a list of parts in column A that I loop through and if they are the
same I get the data from colunm B that matches all the same values in column
A and insert it into C1.

colA ColB
door 1234
door 1234
door 5555
hood 5555
hood 6666
hood 1234

The output would be
col A Col C
door 1234, 5555
hood 5555,6666,1234


"Jim Cone" wrote:
Are you comparing Cell "A1" to the rest of the cells in column A or
are you looking for duplicates in column A ?
You could get a start on figuring out the problem by declaring all of your variables.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



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
Delete records when certain records have duplicate column data JVroom New Users to Excel 1 January 26th 09 06:23 PM
draw 999 x 8 random records from file with 8614 records news.wanadoo.nl Excel Programming 1 March 1st 06 03:04 PM
Delete two records together with looping mikeburg[_81_] Excel Programming 2 February 21st 06 05:16 PM
urgent. looping thru all records and applynig formula to get new results shirley Excel Programming 2 April 29th 04 04:32 AM
Looping Through Records. Diana[_5_] Excel Programming 6 December 2nd 03 05:40 PM


All times are GMT +1. The time now is 04:07 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"