I am trying to do a horizontal sort for 6 columns of data per row. I then want to concat all 6 columns into one single cell. The VBA code I am using works fine except for a situation in which there is an empty cell between two columns of data.
As per the example below, code works fine for first two records. I get a run-time error at the third record because the cell in second column is blank. (sample attached with expected results, if needed). Thanks
Column 1.........Column 2..............Column3..........Expected Result
2222...............5555.............................................22225555
5555...............2222.............................................22225555
5555............................................2222................22225555
Sub HorizontalRepSort()
With Sheets("FullFile")
Lastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("W2:W" & Lastrow).ClearContents
For i = 2 To Lastrow
Application.StatusBar = "Analyzing " & i - 1 & " of " & Lastrow - 1 & " records for rep IDs 1-6."
ActiveRepCount = WorksheetFunction.CountA(.Range("Q" & i & ":V" & i))
'Concat reps IDs 1-6 and sort ascending
For y = 1 To ActiveRepCount
MinimumRepValue = Application.WorksheetFunction.Small(.Range("Q" & i).Resize(, ActiveRepCount), y)
.Range("W" & i) = "'" & .Range("W" & i) & MinimumRepValue
Next
Next
End With
End Sub
For example:
Bookmarks