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

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
407
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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
No, there is no NULL in Excel.
 
Upvote 0
A follow up if you please -

So what/how would you recommend placing "nothing" in a cell(s)?
What alternative could there be to do a Range(Selection, Selection.End(xlUp)).Select and only selecting cells that are >0 (or something like that) where there would be only "blank" cells in the upper most row. All the values would follow the blank cells (or ones with text)?

EDIT - I'm still interested in the question here but I may have to rethink this a bit. If you have any suggestions to this I'm still most certainly interested.
I'll be Back. . .
 
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.
 
Upvote 0
Try This
Sub Range_Selection()
Dim lastrow As Long
lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
Dim i As Integer
i = 2
For i = 2 To lastrow
If Range("b" & i).Value > 1 Then
Range("B" & i).Select
Exit For
Else
End If
Next i
Range(Selection, Selection.End(xlDown)).Select
end Sub
 
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)

1724353805051.png
 
Last edited:
Upvote 0
Solution
@MARK858 i have created based on the attached snip.


for above scenario below code will work.
Sub RANGESET()

Dim lastrow As Long
lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
Dim i As Integer
i = 2
For i = 2 To lastrow
If IsNumeric(Range("b" & i).Value) And IsNumeric(Range("b" & i).Value > 1) Then
Range("B" & i).Select
Exit For
Else
End If
Next i
Range(Selection, Selection.End(xlDown)).Select
End Sub
 

Attachments

  • Capture.JPG
    Capture.JPG
    32 KB · Views: 13
Upvote 0
So how are you recommending placing Nothing in the cells (as per your snip) as the OP is using a formula?

Btw the i = 2 is doing nothing as the next line tells it to start at 2

VBA Code:
i = 2
For i = 2 To lastrow
 
Last edited:
Upvote 0
he mentioned
alternative could there be to do a Range(Selection, Selection.End(xlUp)).Select and only selecting cells that are >0 (or something like that)
 
Upvote 0
You can't just ignore that "" is treated as greater than zero
 
Upvote 0

Forum statistics

Threads
1,224,259
Messages
6,177,480
Members
452,782
Latest member
ZCapitao

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