Can you add NULL (not Blank "") to an If statement in a formula?

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
358
Office Version
  1. 2007
Platform
  1. Windows
Hello,

I’m just trying something here. Is there a way to add a NULL value to a cell (not “”) via a formula? The reason I ask about this is I believe the NULL option reacts differently than a blank “” entry.

I placed a formula =If(A1<=0,NULL,100) in range B1 and copied down thru B10.
B2 is =If(A2<=0,NULL,100), B3 is =If(A3<=0,NULL,100), . . . B10 is =If(103<=0,NULL,100).

As example only –
Range A1:A5 contains zeros (or some text) and range A6:A10 have values in them. I want to set a range only for the area that has values (i.e., B6:B10).

If I code something like:
VBA Code:
   Range(“B10”).Select
   Range(Selection, Selection.End(xlUp)).Select

With a formula using a blank “” option (i.e., If(A1<=0,””,100) the range will be B1:B10. Since B1:B5 appear to be blank but do contain “”. I was hoping if I could insert a NULL into B1:B5 then when I run the Selection.End.(xlUp) process it would only select B10:B6.

Thanks for viewing,
Steve
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
@EssKayKay not ideal (both codes will select negative numbers or zero's in column B but by post 1 you will only have 100 or "" in the cells) but what about
VBA Code:
Range("B1:B10").SpecialCells(xlCellTypeFormulas, 1).Select

Although as Rory stated you rarely need to select the cells to work with them in VBA so it depends what you are doing with the code afterwards

Book1
AB
10 
20 
3dddd100
40 
50 
61100
72100
83100
94100
105100
Sheet1
Cell Formulas
RangeFormula
B1:B10B1=IF(A1<=0,"",100)


1724355770146.png


Or
VBA Code:
    Dim myRng As Range

    Set myRng = Range("A1:A10").SpecialCells(xlCellTypeConstants, 1)
    myRng.Offset(, 1).SpecialCells(xlCellTypeFormulas, 1).Select

1724356530384.png
 
Last edited:
Upvote 0
You can't place nothing in a cell that has a formula in it (in spite of many requests for a BLANK() function like DAX has).

The best solution will depend on why there are 'blank' cells and what you are actually doing. It might be filtering, or looping. Selecting cells at all is almost never necessary though.
Thanks Rory. I'll try to do this a bit differently. I will create another post when I get this
@RajeshKumar1313 did you test this with the OP's scenario?


Book1
AB
10 
20 
3dddd100
40 
50 
61100
72100
83100
94100
105100
Sheet1
Cell Formulas
RangeFormula
B1:B10B1=IF(A1<=0,"",100)


Result I got is below (which is what I expected)

View attachment 115831

I think this is getting really close to what I had in mind. I'm going to look at this closer tomorrow. I have another issue I'm working on. I will get back to you and Rory. I thank you both for your time and suggestions. I'll keep you posted.

Again, so appreciated,
Steve K.
 
Upvote 0
@RajeshKumar1313 did you test this with the OP's scenario?


Book1
AB
10 
20 
3dddd100
40 
50 
61100
72100
83100
94100
105100
Sheet1
Cell Formulas
RangeFormula
B1:B10B1=IF(A1<=0,"",100)


Result I got is below (which is what I expected)

View attachment 115831

Hey Mark - I'm back,
I ran into a problem when attempting to add your code and my full worksheet. It worked great with my sample info which I originally include here.

However, my actual code is =IF(M33>0,"",C33) which is placed in column V. I assume the reason this is not working as expected is because the column numbers etc. don’t match your code (based on my sample example).

I apologize if this comes off as being a bit demanding here which I surely don’t mean to be, but could you review/modify your code to reflect my exact column and formulas?

Sorry for such a request but I am not a programmer -- but I try. I hope you understand

Thanks again,
Steve
 
Upvote 0
Mark,
I noticed some other problems, namely (like in my sample) there can be blank cells at the end. I only want the range to be cells with a 100. In my example below I would want the range to be B7:B10 even though there is data in rows 11&12.

1724386605279.png


For right now, let's just put this on hold. I've got another idea.
Thank you for your support and assistance. Sorry for being such a pest.
 
Upvote 0
I know you said that you have it on hold but having blank cells at the end shouldn't make a difference (even if they aren't blank but "")

With ""
Book1
AB
40 
50 
61100
72100
83100
94100
105100
110 
120 
Sheet1
Cell Formulas
RangeFormula
B4:B12B4=IF(A4<=0,"",100)


I get
1724443838707.png



With blank cells

Book1
AB
40 
50 
61100
72100
83100
94100
105100
110
120
Sheet1
Cell Formulas
RangeFormula
B4:B10B4=IF(A4<=0,"",100)


I get

1724443980840.png


As for
However, my actual code is =IF(M33>0,"",C33) which is placed in column V.
Then you would need to adjust the offset something like

Rich (BB code):
    Dim myRng As Range

    Set myRng = Range("M33:M43").SpecialCells(xlCellTypeConstants, 1)
    myRng.Offset(, 9).SpecialCells(xlCellTypeFormulas, 1).Select
Which would give
Book1
BCDMNV
331000100
340100
351 
362 
373 
384 
395 
400100
410100
Sheet1
Cell Formulas
RangeFormula
V33:V41V33=IF(M33>0,"",$C$33)


1724444583287.png
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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