The purpose of this code is to take a specific item from a Master Sheet so it can analyze it and use conditional formatting to assign it to a specific color sheet. I tried to make it simple by copying that row to its respective sheet and then just pasting it to the next available row using an xlUp and offset command. When I run this code in the debugger, it works perfectly fine when I go through each step slowly. However, when I try to run the code using full runtime or debug it quickly, it skips the step for it to get pasted to the next available line. Could anybody help me with this issue?
Sub Sort_Sheets()
Dim ColorRow As Long, NewRows As Range, MasRow As Range, ColorCol As String
Dim MastSheet As Worksheet, ColorVal As Variant, lastRow As Variant
Set Master = Worksheets("Master Sheet")
ColorRow = 2
ColorCol = "D"
ColorVal = Master.Cells(ColorRow, ColorCol).Value
Sheets(Array("Gray", "Pink", "Purple", "Yellow", "Orange", "Blue", "Rare", "Black", _
"Red", "Green", "White")).Select
Sheets("Gray").Activate
Range("A2:I2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("J2").Select
Sheets("Gray").Select
Application.CutCopyMode = False
Master
While ColorVal <> ""
ColorVal = Master.Cells(ColorRow, ColorCol).Value
If InStr(1, ColorVal, "WHITE", vbTextCompare) <> 0 Then
Master.Rows(ColorRow).Copy Destination:=Worksheets("White").Rows(ColorRow)
If ColorRow > 2 Then
Rows(ColorRow).Select
Selection.Copy Destination:=Selection.End(xlUp).Offset(1, 0)
Selection.Delete
Application.CutCopyMode = False
End If
ElseIf InStr(1, ColorVal, "RED", vbTextCompare) <> 0 Then
Master.Rows(ColorRow).Copy Destination:=Worksheets("Red").Rows(ColorRow)
If ColorRow > 2 Then
Rows(ColorRow).Select
Selection.Copy
Selection.End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlValues
Selection.Delete
Application.CutCopyMode = False
End If
ElseIf InStr(1, ColorVal, "GREEN", vbBinaryCompare) <> 0 Then
Master.Rows(ColorRow).Copy Destination:=Worksheets("GREEN").Rows(ColorRow)
If ColorRow > 2 Then
Rows(ColorRow).Select
Selection.Copy Destination:=Selection.End(xlUp).Offset(1, 0)
Selection.Delete
Application.CutCopyMode = False
End If
ElseIf InStr(1, ColorVal, "BLACK", vbBinaryCompare) <> 0 Then
Master.Rows(ColorRow).Copy Destination:=Worksheets("Black").Rows(ColorRow)
If ColorRow > 2 Then
Rows(ColorRow).Select
Selection.Copy Destination:=Selection.End(xlUp).Offset(1, 0)
Selection.Delete
Application.CutCopyMode = False
End If
ElseIf InStr(1, ColorVal, "GRAY", vbBinaryCompare) <> 0 Then
Master.Rows(ColorRow).Copy Destination:=Worksheets("Gray").Rows(ColorRow)
If ColorRow > 2 Then
Rows(ColorRow).Select
Selection.Copy Destination:=Selection.End(xlUp).Offset(1, 0)
Selection.Delete
Application.CutCopyMode = False
End If
ElseIf InStr(1, ColorVal, "BLUE", vbBinaryCompare) <> 0 Then
Master.Rows(ColorRow).Copy Destination:=Worksheets("Blue").Rows(ColorRow)
If ColorRow > 2 Then
Rows(ColorRow).Select
Selection.Copy Destination:=Selection.End(xlUp).Offset(1, 0)
Selection.Delete
Application.CutCopyMode = False
End If
ElseIf InStr(1, ColorVal, "ORANGE", vbBinaryCompare) <> 0 Then
Master.Rows(ColorRow).Copy Destination:=Worksheets("Orange").Rows(ColorRow)
If ColorRow > 2 Then
Rows(ColorRow).Select
Selection.Copy Destination:=Selection.End(xlUp).Offset(1, 0)
Selection.Delete
Application.CutCopyMode = False
End If
ElseIf InStr(1, ColorVal, "YELLOW", vbBinaryCompare) <> 0 Then
Master.Rows(ColorRow).Copy Destination:=Worksheets("Yellow").Rows(ColorRow)
If ColorRow > 2 Then
Rows(ColorRow).Select
Selection.Copy Destination:=Selection.End(xlUp).Offset(1, 0)
Selection.Delete
Application.CutCopyMode = False
End If
End If
ColorRow = ColorRow + 1
Wend
End Sub