I currently trying to clean up a large dataset using Excel VBA. The dataset structure looks like this.
However, I would like to make it look like this instead, whereby if the cells in columns A:D all contain the same value, transpose the cells in column E. (And remove the duplicated cells from A:D)
Here is the code I did
Dim ws As Worksheet: Set ws = Sheets("test")
lastrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Dim j As Integer
j = 6
For i = 2 To lastrow
If (Range("A" & i).Value = Range("A" & i + 1).Value) And (Range("B" & i).Value = Range("B" & i + 1).Value) And (Range("C" & i).Value = Range("C" & i + 1).Value) Then
Cells(i, j).Value = Cells(i + 1, 5).Value
j = j + 1
End If
'Reset J back to 6 if columns A to D does not match previous
If (Range("A" & i).Value <> Range("A" & i + 1).Value) Or (Range("B" & i).Value <> Range("B" & i + 1).Value) Or (Range("C" & i).Value <> Range("C" & i + 1).Value) Then
j = 6
End If
Next i
How can this be done?