ThrottleWorks
Excel Ninja
Hi @Luke M Sir,
Sorry to disturb you again on this.
I am facing problem with "wsDest.Cells(outputRow, 5).Value = Left(strCode, Len(strCode) - Len(deLim))" of the below mentioned code.
When I have volume as mentioned below I am getting result as
"
4,354,414,495,666,590,000,000,000,000
"
Volume
435
435
441
449
566
659
665
720
761
1287
Kindly help if you get time.
Sorry to disturb you again on this.
I am facing problem with "wsDest.Cells(outputRow, 5).Value = Left(strCode, Len(strCode) - Len(deLim))" of the below mentioned code.
When I have volume as mentioned below I am getting result as
"
4,354,414,495,666,590,000,000,000,000
"
Volume
435
435
441
449
566
659
665
720
761
1287
Kindly help if you get time.
Code:
Sub Consolidate()
Dim wsDest As Worksheet
Dim wsSource As Worksheet
Dim lastRow As Long
Dim curRow As Long
Dim outputRow As Long
Dim startRow As Long
Const deLim As String = ","
Dim strName As String
Dim strTeam As String
Dim strModel As String
Dim strVol As String
Dim strCode As String
'===========
'ASSUMPTION
'Data has been sorted before running macro
'===========
'Define our sheets
Set wsSource = ThisWorkbook.Worksheets("Sheet1")
Set wsDest = ThisWorkbook.Worksheets.Add
Application.ScreenUpdating = False
outputRow = 3
startRow = 3
With wsSource
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'Load initial values
strName = .Cells(startRow, 1).Value
strTeam = .Cells(startRow, 2).Value
strModel = .Cells(startRow, 3).Value
strVol = .Cells(startRow, 4).Value & deLim
strCode = .Cells(startRow, 5).Value & deLim
For curRow = startRow + 1 To lastRow
If .Cells(curRow, 1).Value = strName And _
.Cells(curRow, 2).Value = strTeam And _
.Cells(curRow, 3).Value = strModel Then
'check if value already logged
If Not (InStr(1, strVol, .Cells(curRow, 4), vbBinaryCompare) > 0) Then
strVol = strVol & .Cells(curRow, 4).Value & deLim
End If
If Not (InStr(1, strCode, .Cells(curRow, 5), vbBinaryCompare) > 0) Then
strCode = strCode & .Cells(curRow, 5).Value & deLim
End If
Else
wsDest.Cells(outputRow, 1).Value = strName
wsDest.Cells(outputRow, 2).Value = strTeam
wsDest.Cells(outputRow, 3).Value = strModel
wsDest.Cells(outputRow, 4).Value = Left(strVol, Len(strVol) - Len(deLim))
wsDest.Cells(outputRow, 5).Value = Left(strCode, Len(strCode) - Len(deLim))
outputRow = outputRow + 1
strName = .Cells(curRow, 1).Value
strTeam = .Cells(curRow, 2).Value
strModel = .Cells(curRow, 3).Value
strVol = .Cells(curRow, 4).Value & deLim
strCode = .Cells(curRow, 5).Value & deLim
End If
Next curRow
'Capture last row
wsDest.Cells(outputRow, 1).Value = strName
wsDest.Cells(outputRow, 2).Value = strTeam
wsDest.Cells(outputRow, 3).Value = strModel
wsDest.Cells(outputRow, 4).Value = Left(strVol, Len(strVol) - Len(deLim))
wsDest.Cells(outputRow, 5).Value = Left(strCode, Len(strCode) - Len(deLim))
End With
'Setup output sheet
With wsDest
.Range("A1").Value = "Output"
.Range("A2:E2").Value = wsSource.Range("A2:E2").Value
.Range("A:E").EntireColumn.AutoFit
.Range("A:E").HorizontalAlignment = xlLeft
End With
Application.Goto wsDest.Range("A1")
Application.ScreenUpdating = True
End Sub