ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel loop Need help (https://www.excelbanter.com/excel-programming/367660-excel-loop-need-help.html)

dlh[_10_]

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


Tom Ogilvy

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 5
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




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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com