If cell equals true then other cell equals off

timlh42

Board Regular
Joined
Sep 27, 2017
Messages
76
I am trying to write some vba code to be able to do the following:

If cell p9 equals True, then B10 equals OFF.

I have tried

If Sheet2.Range("B9").Value > "" And Sheet2.Range("P9").Value = "TRUE" Then
Sheet2.Range("B10").Value = "OFF"


I have made P9 equal True and I still get no result whatsoever.

I can't seem to find what I'm missing.

Can anyone help?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Code:
Sub Off()

If (Range("P1").Value = True And Range("B9").Value = "") Then
Range("B10").Value = "OFF"
End If
End Sub
Note that True is not quoted, it is a Boolean value and not a string.
 
Upvote 0
Sweet!!! Works flawlessly!!!!!!!

Thank You so much!!!!!

I do have one more question though. Since I have 117 rows to do this same comparison, is there any way to keep from having to enter this same line of code 117 times?
 
Last edited:
Upvote 0
Yes, we could do a reiteration.
I'm not sure if this will give the result that you require but it does what you have asked.
In a test I wrote True in each cell within the range P1:P10. When running the macro I had every second row appearing as "OFF".

Anyway, the code:
Code:
Sub Off_More_Rows()
Dim x As Long
For x = 1 To 117
If (Range("P" & x).Value = True And Range("B" & x + 9).Value = "") Then
Range("B" & x + 10).Value = "OFF"
End If
Next
End Sub
 
Upvote 0
Great. I had some doubts when I saw my test. Thank you.

This could have been simpler if you hadn't want to use VBA.
I placed this formula in B10 and dragged down:
=IF(AND(P1=TRUE,B9=""),"OFF","")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,612
Members
452,660
Latest member
Zatman

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