Hi-
I posted this a while back, and am looking for a way to extend the column range, but keep running into an error.
Here is the code that I am currently using, but it is deleting any information beyond the 7th column:
I posted this a while back, and am looking for a way to extend the column range, but keep running into an error.
I am looking for a way to roll up years into ranges if all other fields are the same. For example:
SKU Start Year End Year Make Model Sub Model
123123 1995 1995 Ford F150 King Ranch
123123 1996 1996 Ford F150 King Ranch
123123 1997 1997 Ford F150 King Ranch
123123 1996 1996 Ford F150
123123 1997 1997 Ford F150
123123 1998 1998 Ford F150
Should become:
SKU Start Year End Year Make Model Sub Model
123123 1995 1997 Ford F150 King Ranch
123123 1996 1998 Ford F150
Thanks in advance!
Here is the code that I am currently using, but it is deleting any information beyond the 7th column:
Sub RollUpYear()
Dim LastRow As Long
Dim LastColumn As Long
Dim i As Long
Application.ScreenUpdating = False
With ActiveSheet.UsedRange
LastRow = .Rows.Count + .Rows(1).Row - 1
LastColumn = .Columns.Count + .Columns(1).Column - 1
End With
Cells(1, LastColumn + 1).Value = "Concatenated Values"
Range(Cells(2, LastColumn + 1), Cells(LastRow, LastColumn + 1)).FormulaR1C1 = "=RC1&""#""&RC4&""#""&RC5&""#""&RC6&""#""&RC7"
With Range(Cells(1, 1), Cells(LastRow, LastColumn + 1))
.Sort key1:=Cells(1, LastColumn + 1), order1:=xlAscending, _
key2:=Cells(1, 2), order2:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
For i = LastRow To 2 Step -1
If Cells(i, LastColumn + 1) = Cells(i - 1, LastColumn + 1) Then
If Cells(i, "B").Value - 1 = Cells(i - 1, "C").Value Then
Cells(i - 1, "C").Value = Cells(i, "C").Value
Rows(i).Delete
End If
End If
Next i
Cells(1, LastColumn + 1).EntireColumn.Delete
Application.ScreenUpdating = True
MsgBox "Completed...", vbInformation
End Sub