The first macro creates four worksheets, names them, then searches the original worksheet for string words and colors them based off of RBG and sort them. I never have an issue running this macro.
My second macro should cut/paste things into their specified worksheet. It never works.
Macro 1 that creates worksheets, color codes, and sorts.
Sub MacroTest3()
' MacroTest3 Macro
'
'
Sheets.Add After:=ActiveSheet
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "DNIF"
Sheets.Add After:=ActiveSheet
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "Wx"
Sheets.Add After:=ActiveSheet
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Preg"
Sheets.Add After:=ActiveSheet
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "<30"
Range("G34").Select
Sheets("Down Weekly").Select
Range("A1:A2").Select
Selection.Copy
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Sheets("DNIF").Select
ActiveSheet.Paste
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("D:F").Select
Selection.Delete Shift:=xlToLeft
Columns("E:I").Select
Selection.Delete Shift:=xlToLeft
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft
Rows("1:3").Select
Selection.Delete Shift:=xlUp
Cells.Select '------ selects all cell command!
'------------------------------------------------------------------------------'
' Looks for string "Waiver Log" then colors it Yellow
Selection.FormatConditions.Add Type:=xlTextString, String:="Waiver Log", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 255, 0)
.TintAndShade = 0
End With
'------------------------------------------------------------------------------'
' Looks for string "Waiver Hold" then colors it Yellow
Selection.FormatConditions.Add Type:=xlTextString, String:="Waiver Hold", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 255, 0)
.TintAndShade = 0
End With
'------------------------------------------------------------------------------'
' Looks for string "Pregn" then colors it Red
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlTextString, String:="Pregn", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 0, 0)
.TintAndShade = 0
End With
'---------------------------------------------------------------------------------'
' Sorts less than 30 days then colors cels orange
Columns("D:D").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=D2>TODAY()-31"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 192, 0)
End With
Selection.FormatConditions(1).StopIfTrue = False
'---------------------------------------------------------------------------------'
' Sorts Red cells to the top, yellow cells bellow it:
Sheets("DNIF").Select
Range("A1:G1").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("DNIF").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("DNIF").Sort.SortFields.Add(Range("G2:G1000"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0 _
, 0)
ActiveWorkbook.Worksheets("DNIF").Sort.SortFields.Add(Range("G2:G1000"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, _
255, 0)
ActiveWorkbook.Worksheets("DNIF").Sort.SortFields.Add(Range("D2:D1000"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, _
192, 0)
With ActiveWorkbook.Worksheets("DNIF").Sort
.SetRange Range("A1:G1000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'-----------------------------------------------------------------------'
' Copies the headers onto the different worksheets
Range("A1:G1").Select
Selection.Copy
Sheets("Wx").Select
ActiveSheet.Paste
Sheets("Preg").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("<30").Select
Range("A1").Select
ActiveSheet.Paste
End Sub
Second Macro to cut/paste rows based off of RBG color
Sub Copier()
Dim TransIDField As Range
Dim TransIDCell As Range
Dim OriginSheet As Worksheet
Dim TargetSheet As Worksheet
Dim TargetSheet2 As Worksheet
Set OriginSheet = Worksheets("Down Weekly")
Set TransIDField = OriginSheet.Range("G2", OriginSheet.Range("G2").End(xlDown))
Set TargetSheet = Worksheets("Preg")
Set TargetSheet2 = Worksheets("Wx")
For Each TransIDCell In TransIDField
If TransIDCell.Interior.Color = RGB(255, 0, 0) Then
TransIDCell.Resize(1, 7).Cut Destination:= _
TargetSheet.Range("A1").Offset(TargetSheet.Rows.Count - 1,
0).End(xlUp).Offset(1, 0)
End If
Next TransIDCell
For Each TransIDCell In TransIDField
If TransIDCell.Interior.Color = RGB(255, 255, 0) Then
TransIDCell.Resize(1, 7).Cut Destination:= _
TargetSheet2.Range("A1").Offset(TargetSheet2.Rows.Count - 1,
0).End(xlUp).Offset(1, 0)
End If
Next TransIDCell
End Sub