Hello,
I have the following code to sort through three different columns. If Column 5 is empty, it needs to be filled in with the specified color. However, there are times that column 5 may not be empty. When there are no empty cells in column 5, it turns all three columns(5,6,7) all blue. How can I prevent this from happening? Also, this code seems to take forever to run. Is there anyway to make it faster? The number of rows of data changes every time I pull this specific report so I put a large number(2500) to read to the bottom. This slows the Macro down, can it be made to where it finds the last row of data so the code will run faster?
Sub Jones1413()
Dim lastRowFilled
lastRowFilled = 2500
For iCntr = lastRowFilled To 1 Step -1
If Rows(iCntr).Hidden = True Then Rows(iCntr).EntireRow.Delete
Next
Dim Usdrws As Long
With ActiveSheet
Usdrws = Range("A" & Rows.Count).End(xlUp).Row
.Range("A1:K" & Usdrws).AutoFilter 5, ""
.AutoFilter.Range.Offset(1).Columns(5).Resize(Usdrws - 1).Interior.Color = 16776960
.Range("A1:K" & Usdrws).AutoFilter 5
.Range("A1:K" & Usdrws).AutoFilter 5, ""
.Range("A1:K" & Usdrws).AutoFilter 6, ""
.Range("A1:K" & Usdrws).AutoFilter 7, ""
.AutoFilter.Range.Offset(1).Columns(6).Resize(Usdrws - 1).Interior.Color = 16776960
.AutoFilter.Range.Offset(1).Columns(7).Resize(Usdrws - 1).Interior.Color = 16776960
.Range("A1:K" & Usdrws).AutoFilter 7
.Range("A1:K" & Usdrws).AutoFilter 6
.Range("A1:K" & Usdrws).AutoFilter 5
.Range("A1:K" & Usdrws).AutoFilter 5, "Internal"
.Range("A1:K" & Usdrws).AutoFilter 6, ""
.AutoFilter.Range.Offset(1).Columns(6).Resize(Usdrws - 1).Interior.Color = 16776960
.Range("A1:K" & Usdrws).AutoFilter 6
.Range("A1:K" & Usdrws).AutoFilter 5
.Range("A1:K" & Usdrws).AutoFilter 5, Array("Conversion", "Referral", "Temp-to-hire", "Well"), xlFilterValues
.Range("A1:K" & Usdrws).AutoFilter 7, ""
.AutoFilter.Range.Offset(1).Columns(7).Resize(Usdrws - 1).Interior.Color = 16776960
.Range("A1:K" & Usdrws).AutoFilter 5
.Range("A1:K" & Usdrws).AutoFilter 7
End With
End Sub
I have the following code to sort through three different columns. If Column 5 is empty, it needs to be filled in with the specified color. However, there are times that column 5 may not be empty. When there are no empty cells in column 5, it turns all three columns(5,6,7) all blue. How can I prevent this from happening? Also, this code seems to take forever to run. Is there anyway to make it faster? The number of rows of data changes every time I pull this specific report so I put a large number(2500) to read to the bottom. This slows the Macro down, can it be made to where it finds the last row of data so the code will run faster?
Sub Jones1413()
Dim lastRowFilled
lastRowFilled = 2500
For iCntr = lastRowFilled To 1 Step -1
If Rows(iCntr).Hidden = True Then Rows(iCntr).EntireRow.Delete
Next
Dim Usdrws As Long
With ActiveSheet
Usdrws = Range("A" & Rows.Count).End(xlUp).Row
.Range("A1:K" & Usdrws).AutoFilter 5, ""
.AutoFilter.Range.Offset(1).Columns(5).Resize(Usdrws - 1).Interior.Color = 16776960
.Range("A1:K" & Usdrws).AutoFilter 5
.Range("A1:K" & Usdrws).AutoFilter 5, ""
.Range("A1:K" & Usdrws).AutoFilter 6, ""
.Range("A1:K" & Usdrws).AutoFilter 7, ""
.AutoFilter.Range.Offset(1).Columns(6).Resize(Usdrws - 1).Interior.Color = 16776960
.AutoFilter.Range.Offset(1).Columns(7).Resize(Usdrws - 1).Interior.Color = 16776960
.Range("A1:K" & Usdrws).AutoFilter 7
.Range("A1:K" & Usdrws).AutoFilter 6
.Range("A1:K" & Usdrws).AutoFilter 5
.Range("A1:K" & Usdrws).AutoFilter 5, "Internal"
.Range("A1:K" & Usdrws).AutoFilter 6, ""
.AutoFilter.Range.Offset(1).Columns(6).Resize(Usdrws - 1).Interior.Color = 16776960
.Range("A1:K" & Usdrws).AutoFilter 6
.Range("A1:K" & Usdrws).AutoFilter 5
.Range("A1:K" & Usdrws).AutoFilter 5, Array("Conversion", "Referral", "Temp-to-hire", "Well"), xlFilterValues
.Range("A1:K" & Usdrws).AutoFilter 7, ""
.AutoFilter.Range.Offset(1).Columns(7).Resize(Usdrws - 1).Interior.Color = 16776960
.Range("A1:K" & Usdrws).AutoFilter 5
.Range("A1:K" & Usdrws).AutoFilter 7
End With
End Sub