Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel loop Need help
I have tohe following code and it works for combining the data in
column B1 and B2 into B1 with commas if column A is the same name in A1 and A2. What I am also needing is the data in columns C-E to be merged as well the same. Col A ColB ColC ColD Col E BRAKE LINE RUBBING, KNOCKING 4 BT93 LY52486 8888 BRAKE LINE RUBBING, KNOCKING 4 BU31 LT91873 2807 DIFFERENTI. TRANSMISSION 4 DU53 LF77113 DOOR INNER HANDLE FUNCTION ISSUE 4 BU33 LW59323 1130 DOOR CUT-OUT WELD ISSUE 4 DU91 LK43454 The output of the script would be: BRAKE LINE RUBBING, KNOCKING 4,4 BT93,BU31 LY52486,LT91873 8888,2807 DIFFERENTI. TRANSMISSION 4 DU53 LF77113 DOOR INNER HANDLE FUNCTION ISSUE 4 BU33 LW59323 1130 DOOR CUT-OUT WELD ISSUE 4 DU91 LK43454 Set rngColumn = Range("A1", Cells(Rows.Count, 1).End(xlUp)) For Each rngCell In rngColumn If Len(rngCell.Value) Then varToMatch = rngCell.Value lngR = 2 Do While rngCell(lngR, 1).Value = varToMatch rngCell(1, 2).Value = rngCell(1, 2).Value & ", " & rngCell(lngR, 2).Value 'rngCell(lngR, 2).EntireRow.Clear lngR = lngR + 1 Loop End If Next rngColumn.EntireRow.Sort key1:=Range("A1") End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel loop Need help
Set rngColumn = Range("A1", Cells(Rows.Count, 1).End(xlUp))
For Each rngCell In rngColumn If Len(rngCell.Value) Then varToMatch = rngCell.Value lngR = 2 Do While rngCell(lngR, 1).Value = varToMatch for j = 2 to 4 rngCell(1, j).Value = rngCell(1, j).Value & ", " & _ rngCell(lngR, j).Value Next j 'rngCell(lngR, 2).EntireRow.Clear lngR = lngR + 1 Loop End If Next rngColumn.EntireRow.Sort key1:=Range("A1") End Sub -- Regards, Tom Ogilvy "dlh" wrote: I have tohe following code and it works for combining the data in column B1 and B2 into B1 with commas if column A is the same name in A1 and A2. What I am also needing is the data in columns C-E to be merged as well the same. Col A ColB ColC ColD Col E BRAKE LINE RUBBING, KNOCKING 4 BT93 LY52486 8888 BRAKE LINE RUBBING, KNOCKING 4 BU31 LT91873 2807 DIFFERENTI. TRANSMISSION 4 DU53 LF77113 DOOR INNER HANDLE FUNCTION ISSUE 4 BU33 LW59323 1130 DOOR CUT-OUT WELD ISSUE 4 DU91 LK43454 The output of the script would be: BRAKE LINE RUBBING, KNOCKING 4,4 BT93,BU31 LY52486,LT91873 8888,2807 DIFFERENTI. TRANSMISSION 4 DU53 LF77113 DOOR INNER HANDLE FUNCTION ISSUE 4 BU33 LW59323 1130 DOOR CUT-OUT WELD ISSUE 4 DU91 LK43454 Set rngColumn = Range("A1", Cells(Rows.Count, 1).End(xlUp)) For Each rngCell In rngColumn If Len(rngCell.Value) Then varToMatch = rngCell.Value lngR = 2 Do While rngCell(lngR, 1).Value = varToMatch rngCell(1, 2).Value = rngCell(1, 2).Value & ", " & rngCell(lngR, 2).Value 'rngCell(lngR, 2).EntireRow.Clear lngR = lngR + 1 Loop End If Next rngColumn.EntireRow.Sort key1:=Range("A1") End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel loop Need help
for j = 2 to 4
should be for j = 2 to 5 -- Regards, Tom Ogilvy "Tom Ogilvy" wrote: Set rngColumn = Range("A1", Cells(Rows.Count, 1).End(xlUp)) For Each rngCell In rngColumn If Len(rngCell.Value) Then varToMatch = rngCell.Value lngR = 2 Do While rngCell(lngR, 1).Value = varToMatch for j = 2 to 4 rngCell(1, j).Value = rngCell(1, j).Value & ", " & _ rngCell(lngR, j).Value Next j 'rngCell(lngR, 2).EntireRow.Clear lngR = lngR + 1 Loop End If Next rngColumn.EntireRow.Sort key1:=Range("A1") End Sub -- Regards, Tom Ogilvy "dlh" wrote: I have tohe following code and it works for combining the data in column B1 and B2 into B1 with commas if column A is the same name in A1 and A2. What I am also needing is the data in columns C-E to be merged as well the same. Col A ColB ColC ColD Col E BRAKE LINE RUBBING, KNOCKING 4 BT93 LY52486 8888 BRAKE LINE RUBBING, KNOCKING 4 BU31 LT91873 2807 DIFFERENTI. TRANSMISSION 4 DU53 LF77113 DOOR INNER HANDLE FUNCTION ISSUE 4 BU33 LW59323 1130 DOOR CUT-OUT WELD ISSUE 4 DU91 LK43454 The output of the script would be: BRAKE LINE RUBBING, KNOCKING 4,4 BT93,BU31 LY52486,LT91873 8888,2807 DIFFERENTI. TRANSMISSION 4 DU53 LF77113 DOOR INNER HANDLE FUNCTION ISSUE 4 BU33 LW59323 1130 DOOR CUT-OUT WELD ISSUE 4 DU91 LK43454 Set rngColumn = Range("A1", Cells(Rows.Count, 1).End(xlUp)) For Each rngCell In rngColumn If Len(rngCell.Value) Then varToMatch = rngCell.Value lngR = 2 Do While rngCell(lngR, 1).Value = varToMatch rngCell(1, 2).Value = rngCell(1, 2).Value & ", " & rngCell(lngR, 2).Value 'rngCell(lngR, 2).EntireRow.Clear lngR = lngR + 1 Loop End If Next rngColumn.EntireRow.Sort key1:=Range("A1") End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel loop Need help
I declare j as long and it worked perfect Tom Ogilvy wrote: for j = 2 to 4 should be for j = 2 to 5 -- Regards, Tom Ogilvy "Tom Ogilvy" wrote: Set rngColumn = Range("A1", Cells(Rows.Count, 1).End(xlUp)) For Each rngCell In rngColumn If Len(rngCell.Value) Then varToMatch = rngCell.Value lngR = 2 Do While rngCell(lngR, 1).Value = varToMatch for j = 2 to 4 rngCell(1, j).Value = rngCell(1, j).Value & ", " & _ rngCell(lngR, j).Value Next j 'rngCell(lngR, 2).EntireRow.Clear lngR = lngR + 1 Loop End If Next rngColumn.EntireRow.Sort key1:=Range("A1") End Sub -- Regards, Tom Ogilvy "dlh" wrote: I have tohe following code and it works for combining the data in column B1 and B2 into B1 with commas if column A is the same name in A1 and A2. What I am also needing is the data in columns C-E to be merged as well the same. Col A ColB ColC ColD Col E BRAKE LINE RUBBING, KNOCKING 4 BT93 LY52486 8888 BRAKE LINE RUBBING, KNOCKING 4 BU31 LT91873 2807 DIFFERENTI. TRANSMISSION 4 DU53 LF77113 DOOR INNER HANDLE FUNCTION ISSUE 4 BU33 LW59323 1130 DOOR CUT-OUT WELD ISSUE 4 DU91 LK43454 The output of the script would be: BRAKE LINE RUBBING, KNOCKING 4,4 BT93,BU31 LY52486,LT91873 8888,2807 DIFFERENTI. TRANSMISSION 4 DU53 LF77113 DOOR INNER HANDLE FUNCTION ISSUE 4 BU33 LW59323 1130 DOOR CUT-OUT WELD ISSUE 4 DU91 LK43454 Set rngColumn = Range("A1", Cells(Rows.Count, 1).End(xlUp)) For Each rngCell In rngColumn If Len(rngCell.Value) Then varToMatch = rngCell.Value lngR = 2 Do While rngCell(lngR, 1).Value = varToMatch rngCell(1, 2).Value = rngCell(1, 2).Value & ", " & rngCell(lngR, 2).Value 'rngCell(lngR, 2).EntireRow.Clear lngR = lngR + 1 Loop End If Next rngColumn.EntireRow.Sort key1:=Range("A1") End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
For Each ... Next loop - need to reference the loop variable | Excel Programming | |||
Advancing outer Loop Based on criteria of inner loop | Excel Programming | |||
Loop Function unable to loop | Excel Programming | |||
Problem adding charts using Do-Loop Until loop | Excel Programming | |||
HELP!!!! Can't stop a loop (NOT an infinite loop) | Excel Programming |