I have cells with data
I get the number with
then I want to give the cell a color I am trying with but not working I get type mismatch, been trying for couple of hours and getting no where.
Sub Format() Dim LastRow As Long Dim WS As Worksheet Set WS = Sheets("sheet1") LastRow = WS.range("F" & WS.Rows.Count).End(xlUp).Row If WS.range("F2:F" & LastRow).Formula = "=Value(Left(Right(F2, 2)))" < 3 Then cell.Interior.ColorIndex = 10 End Sub
Sub Format() Dim LastRow As Long Dim WS As Worksheet dim rCell as range Set WS = Sheets("sheet1") LastRow = WS.range("F" & WS.Rows.Count).End(xlUp).Row for each rcell in WS.range("F2:F" & LastRow).cells if clng(Left(Right(rcell.value, 2), 1)) < 3 Then rcell.Interior.ColorIndex = 10 next rcell End Sub
Instead of using VBA, use Conditional Formatting.
Say your cells from F1 to F10 contain values such as Peer(2), Peer(3), Peer(1) etc
- Select the Range F1 to F10 (or to any cell which you want formatted)
- On the ribbon, click on “Conditional Formatting” -> “New Rule”
- Choose “Use a formula to determine which cells to format”
- Assuming the active cell is F1, type in the formula
=VALUE(LEFT(RIGHT(F1,2))) < 3
- Click on “Format” button, go to “Fill” tab, click on “More Colors”, “Custom” tab.
- Put 128 for Green, 0 for Red and Blue.
- Click “OK” till the dialog closes.
Hope that helps.