I am trying to write code that would shift the range of cells from the current cell till the last cell that has data in the row one cell to the right if the relative cell that contains the weekday has the values fri
or sat
.
My code is below, however when it runs, Excel would not respond and restarts by itself. I don't really know where the problem is.
Note: i
is the row index
, j
is the column index
Sub shiftcell()
Dim i As Integer
Dim j As Integer
Dim lcol As Integer
Dim rng As Range
For i = 8 To 18
For j = 6 To 70
If (Sheets("master").Cells(6, j).Value = "Fri" Or
Sheets("master").Cells(6, j).Value = "Sat") Then
lcol = Sheets("MASTER").Cells(i, Columns.COUNT).End(xlToLeft).Column
Set rng = Range(Cells(i, j), Cells(i, lcol))
rng.Cut rng.Cells(i).Offset(0, 1)
End If
Next j
Next i
End Sub