Validate

kenpcli

Board Regular
Joined
Oct 24, 2017
Messages
129
Why wont this script color the column M if it meets both criteria:

Sub Validate()


Dim found As Boolean
found = False
For Each cell In Range("F2:M1000").Cells
If cell.Value = "FT Hourly" And "<40" Then
found = True
End If
Next
If found = True Then
cell.Select.Interior.ColorIndex = 9

End If
End Sub

Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
This line:

If cell.Value = "FT Hourly" And "<40" Then

is likely the problem. What is the bit in red intended to do?
 
Upvote 0
Can you upload a couple of rows that meet your condition? I'd like to see how the data is structured.
 
Upvote 0
Why wont this script color the column M if it meets both criteria:

Sub Validate()


Dim found As Boolean
found = False
For Each cell In Range("F2:M1000").Cells
If cell.Value = "FT Hourly" And "<40" Then
found = True
End If
Next
If found = True Then
cell.Select.Interior.ColorIndex = 9

End If
End Sub
What exactly is the red highlighted line of code above trying to test for? Either a cell has text in it or it has a number in it, both cannot be true (your use of the And operator makes it seem like you think it can).

Also, what is the overall purpose of this code? There are other structural problems with your code besides the above, but I won't know how to fix them until I know what you want this code to actually do.
 
Last edited:
Upvote 0
I am trying to get it to look at column F (Pay Class)and find any FT Hourly it is FT Hourly then look at Column M (Total) in the same row and see if it is less 40, if so it color fills it.

Home CompanyFull NameID NumberHome SiteHome DepartmentPay Class NameRegular Overtime PTO FTO REGPOR PORSL Total
PCLI-Corp130FT Hourly40.00 40.00
PCLI-Corp130FT Hourly39.95 39.95
PCLI-Corp130FT Hourly40.00 40.00
PCLI-Corp130FT Hourly39.75 39.75
PCLI-Corp130FT Hourly26.80 13.20 40.00
PCLI-Corp130FT Hourly40.00 40.00
PCLI-Corp130FT Hourly31.25 8.75 40.00
PCLI-Corp130FT Hourly40.00 40.00
PCLI-Corp130Hourly PT0.00

<tbody>
</tbody><colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup>
 
Upvote 0
Maybe:
Code:
Sub Validate()
Dim cell As Range
Application.ScreenUpdating = False
For Each cell In Range("F2:F1000")
If cell.Value = "FT Hourly" And cell.Offset(0, 7).Value < 40 Then cell.Offset(0, _
    7).Interior.ColorIndex = 9
Next cell
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Here is another macro for you to consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub Validate()
  Dim R As Long
  Application.ScreenUpdating = False
  For R = 2 To Cells(Rows.Count, "F").End(xlUp).Row
    If Cells(R, "F").Value = "FT Hourly" And Cells(R, "M").Value < 40 Then Cells(R, "M").Interior.ColorIndex = 9
  Next
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,217
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top