'Trying to remove a section of the code that appends rows together
I'm trying to modify the section of this code that appends rows, so that it just overwrites. Everything I try breaks the whole thing. The section im trying to remove is between ('append all other columns if different) and (' now delete the duplicate row)
Sub Consolidate()
Worksheets("1").Activate
Columns("H:BV").EntireColumn.Delete
Dim last_row As Long
Dim row As Long
Dim s As Worksheet
Dim col As Integer
Set s = ThisWorkbook.Worksheets("1") ' use this line to process a specific sheet
last_row = s.Cells(s.Rows.Count, 1).End(xlUp).row 'find the last row with data
For row = last_row To 3 Step -1
If s.Cells(row, "D").Value = s.Cells(row - 1, "D").Value Then
' found a match in column d
' add column F
s.Cells(row - 1, "F").Value = s.Cells(row - 1, "F").Value + s.Cells(row, "F").Value
' add column G
s.Cells(row - 1, "G").Value = s.Cells(row - 1, "G").Value + s.Cells(row, "G").Value
'append all other columns if different
For col = 1 To 5
If Not s.Cells(row, col).Value = s.Cells(row - 1, col).Value Then
s.Cells(row - 1, col).Value = s.Cells(row - 1, col).Value & " " & s.Cells(row, col).Value
End If
Next
' now delete the duplicate row
s.Rows(row).Delete
End If
Next
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
