Option Explicit
Sub Shwapx_Explained()
Dim ws As Worksheet '<< irrelevant
Dim LRow As Long, LCol As Long '<< irrelevant
Set ws = Worksheets("Sheet1") '<< *** change to actual sheet name
LRow = ws.Cells.Find("*", , xlFormulas, , 1, 2).Row '<< irrelevant
LCol = ws.Cells.Find("*", , xlFormulas, , 2, 2).Column + 1 '<< irrelevant
Application.ScreenUpdating = False '<< irrelevant
'*** The next line starts at row 2 (i.e. "Cells(2,..)
'*** Change the 2 to whatever row your data actually starts on - not the header row
With ws.Range(ws.Cells(2, LCol), ws.Cells(LRow, LCol))
'*** The following line is joining the values in columns A, B and C
'*** You can change these columns to whatever you want - add some, remove some
'*** It currrently refers to row 2 (e.g. "A2:..) - Change this to the first row that
'*** data starts on - not the header row, the actual first row of data
.Value = ws.Evaluate(Replace("A2:A#&"" | ""&B2:B#&"" | ""&C2:C#", "#", LRow))
End With
Dim ArrIn, ArrOut, i As Long '<< irrelevant
'*** The next line gets the array values starting from the header row
'*** or at least the row ABOVE the first row of data - Change this to suit
ArrIn = ws.Range(ws.Cells(1, LCol), ws.Cells(LRow + 1, LCol)) '<< SEE BELOW
ReDim ArrOut(1 To UBound(ArrIn, 1) + 1, 1 To 1) '<< irrelevant
'*** The next block of code should not need to be changed
For i = 2 To UBound(ArrIn, 1) - 1
If ArrIn(i, 1) = ArrIn(i + 1, 1) Or ArrIn(i, 1) = ArrIn(i - 1, 1) Then ArrOut(i, 1) = 1
Next i
'*** The 1 used here (i.e. "Cells(1,..) refers to the row of the headers
'*** Or at least the row ABOVE the first row of data
'*** Make sure it matches the row you indicated in the line above I marked "SEE BELOW"
ws.Cells(1, LCol).Resize(UBound(ArrOut, 1)).Value = ArrOut
'*** This may need to be changed. The ws.Cells(1) refers to cell A1 in worksheet ws
'*** For example, if your header row is on row 6, change it to ws.Cells(6,1)
'*** This method won't work if there's data in the row above the headers
'*** In which case you'll need to use something like the following line (assumes your headers
'*** are on row 5 and there isn't a blank row between the headers and the data
' With ws..Range(Cells(6, 1), Cells(6, LCol))
With ws.Cells(1).CurrentRegion
.AutoFilter LCol, 1
.Offset(1).EntireRow.Delete
.AutoFilter
End With
Application.ScreenUpdating = True '<< irrelevant
End Sub