Why is my IF statement not working?

srosk

Board Regular
Joined
Sep 17, 2018
Messages
132
This is probably a simple one.. but I've tried many different ways and it won't work.

The following calls the next function.

Code:
If Range("E" & r).Value = 6 And Range("F" & r).Value = 6 Then

This does not...

Code:
If Range("E" & r).Value = 6 And Range("F" & r).Value = "_" Then

This also does not work...

Code:
If Range("E" & r).Value = 6 And (Range("F" & r).Value = 4 Or Range("F" & r).Value = 1)  Then

Can anyone help for the above functions? Thank you, as always :)
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Code:
If Range("E" & r).Value = 6 And Range("F" & r).Value = "_" Then
This worked OK for me. You might try
Code:
If Range("E" & r).Value = 6 And Trim(Range("F" & r).Value) = "_" Then
in case you have spaces inthe range.
This one also worked
Code:
If Range("E" & r).Value = 6 And (Range("F" & r).Value = 4 Or Range("F" & r).Value = 1)  Then
You might also need to use the Trim function on this one.

If not, can you be more specific about how they are not working, eg error messages received, etc.
 
Last edited:
Upvote 0
Thanks.. It didn't produce an error before, but based on the criteria, it is supposed to output a message based on the sub function. I will test with the trim function and report back.. tomorrow or Monday. Definitely appreciate you taking a look!

Code:
If Range("E" & r).Value = 6 And Range("F" & r).Value = "_" Then
This worked OK for me. You might try
Code:
If Range("E" & r).Value = 6 And Trim(Range("F" & r).Value) = "_" Then
in case you have spaces inthe range.
This one also worked
Code:
If Range("E" & r).Value = 6 And (Range("F" & r).Value = 4 Or Range("F" & r).Value = 1)  Then
You might also need to use the Trim function on this one.

If not, can you be more specific about how they are not working, eg error messages received, etc.
 
Upvote 0
Also, if there are merged cells in any of the ranges where it does not produce expected results, the merged cell could be causing the problem.
 
Upvote 0
My bad. It was looking for "_" but the value at this point in the spreadsheet was a 0.. later the script updates this column from 0 to _ :rolleyes: wooops!
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,970
Members
449,276
Latest member
surendra75

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