Sub test2()
On Error GoTo EC
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim iArr()
Dim r As Range 'A variable range that will be resized throughout the routine
Dim cel As Range 'A range to step through each cel in r
Dim x As Long 'A number to step through each item in col collection
Dim ic As Long 'A number that will iterate to add each item to iArr() array
Dim rs As Integer 'A number that will be the difference between the non blanks and blanks on each row
Dim cb As Integer 'A number that will be the number of blanks on each row
Dim col As New Collection 'An array of numbers for each row in r that has blanks
Set r = Range("C2:X51565") 'Range of data
r.Cells.Replace What:=" ", Replacement:="", LookAt:=xlWhole, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False 'Replace all " " with ""
Set r = r.SpecialCells(xlCellTypeBlanks) 'Resize to just blank cells
For Each cel In r
col.Add cel.Row(), CStr(cel.Row()) 'Add each row that has blanks to collection
Next cel
For x = 1 To col.Count 'Go through each item in collection
Set r = Range("C" & col(x) & ":X" & col(x)) 'Resize r to specific row
cb = Application.WorksheetFunction.CountBlank(r) 'cb = blank cell count
rs = 22 - cb 'rs = total columns - blank cell count
ReDim iArr(1 To rs) 'Fill array
ic = 1 'Initialize number to iterate for array
For Each cel In r 'for each cel in current row
If cel.Value <> "" Then 'if the cell isn't blank
iArr(ic) = cel.Value 'add to array
ic = ic + 1 'Increment ic
End If
Next cel
r.ClearContents 'Clear out row
Set r = r.Resize(1, r.Cells.Count - cb).Offset(, cb) 'Resize and move range. This is where it is being shifted to the right
r.Value = iArr 'fill range with non blank values
Next x
Exit Sub
EC:
If Err.Number = 457 Then 'To get a unique collection of rows, I add to collection. You can't have duplicate keys in a collection. So as it tries to add the row for each cell that is blank, if the row is the same as one that has been entered into the collection, then it will come here and be told to continue on.
Resume Next
Else 'Any other error will give a number and description and the routine will end.
MsgBox "Error " & Err.Number & " " & Err.Description
Resume Next
End If
Application.ScreenUpdating = True
Application.EnableEvents = False
Application.Calculation = xlCalculationAutomatic
End Sub