Conditional Formatting VBA

riedyp

Board Regular
Joined
Feb 13, 2020
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to do some simple conditional formatting to change the colors of some cells based off the value of one of the others. My "NewRow" variable works for statements before my If statement so i know thats not it. The cell "(NewRow,18)" will be related to a radio button later on so that is why everything will be related to that cell. Please let me know of any suggestions you may have.
VBA Code:
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Button to Add Question
'Add New Question Formatting
Private Sub CommandButton1_Click()
NewRow = Sheet5.Cells(1000, 2).End(xlUp).Row + 2 'Finds the last edited row and then adds two rows
NewNumber = Sheet5.Cells(1000, 1).End(xlUp).Value + 1 'Finds the last question number and adds 1
 Sheet5.Cells(NewRow, 1).Select ' Selects LastRow in the first Column
    ActiveCell.Formula = NewNumber ' Gives it LastNumber
Sheet5.Range("B" & NewRow).Resize(, 11).Interior.Color = RGB(155, 194, 230) 'Changes color for question
Sheet5.Range("B" & NewRow).Resize(, 8).MergeCells = True 'Merges question cells
Sheet5.Range("M" & NewRow).Resize(, 3).MergeCells = True 'Merges answer cells
Sheet5.Cells(NewRow, 10).Select 'YES
 ActiveCell.Value = "YES"
Sheet5.Cells(NewRow, 11).Select 'NO
 ActiveCell.Value = "NO"
 Sheet5.Cells(NewRow, 12).Select 'N/A
 ActiveCell.Value = "N/A"
Sheet5.Rows(NewRow).RowHeight = 28.8 'Set Row Height
Sheet5.Rows(NewRow - 1).RowHeight = 3 'Set Predecessor Row Height
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Conditional Formatting
If Sheet5.Cells(NewRow, 18).Value = 1 Then 'Green box
Sheet5.Cells(NewRow, 16).Interior.ColorIndex = 0 ' Red is no fill
Sheet5.Cells(NewRow, 17).Interior.ColorIndex = 0 ' Yellow is no fill
Sheet5.Cells(NewRow, 18).Interior.ColorIndex = 13561798 'Green is filled
ElseIf Sheet5.Cells(NewRow, 18).Value = 2 Then
Sheet5.Cells(NewRow, 16).Interior.ColorIndex = 13551615 ' Red is filled
Sheet5.Cells(NewRow, 17).Interior.ColorIndex = 0 ' Yellow is no fill
Sheet5.Cells(NewRow, 18).Interior.ColorIndex = 0 'Green is filled
ElseIf Sheet5.Cells(NewRow, 18).Value = 3 Then
Sheet5.Cells(NewRow, 16).Interior.ColorIndex = 0 ' Red is no fill
Sheet5.Cells(NewRow, 17).Interior.ColorIndex = 10284031 ' Yellow is filled
Sheet5.Cells(NewRow, 18).Interior.ColorIndex = 0 'Green is filled
End If
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Change ColorIndex to Color & change the 0s to xlNone
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
When I change the value in (NewRow,18) I have to hit F5 for the value to change. Is there a way to have the sheet auto update so i wont have to hit F5?
 
Upvote 0
That's a new question, so needs a new thread please
 
Upvote 0

Forum statistics

Threads
1,215,669
Messages
6,126,125
Members
449,293
Latest member
yallaire64

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