Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if range is empty

Tags:

range

excel

vba

I want to check if a range in Excel is empty.

How do I write in VBA code:

If Range("A38":"P38") is empty 
like image 305
Kano Avatar asked May 30 '12 06:05

Kano


People also ask

How do you check if a range is empty?

Any time the result is greater than zero, we know that not every cell in the range is blank. To force the formula to return TRUE if every cell is blank, and FALSE if not, we simply add =0 to the end of the formula.

Can you use Isblank on a range?

We can use the ISBLANK coupled with conditional formatting. For example, suppose we want to highlight the blank cells in the range A2:F9, we select the range and use a conditional formatting rule with the following formula: =ISBLANK(A2:F9).

How do you check if a cell is empty in VBA Excel?

If you wish to test whether a worksheet cell is empty in VBA, you can not use the worksheet function called ISBLANK. In VBA, you must use the ISEMPTY function. In this example, we will test whether cell A1 is empty. If cell A1 is empty, the message "Cell A1 is empty" will be displayed.

Is empty in VBA?

VBA IsEmpty is a logical function that tests whether selected is empty or not. Since it is a logical function it will return the results in Boolean values i.e. either TRUE or FALSE. If the selected cell is empty it will return TRUE or else it will return FALSE.


1 Answers

Found a solution from the comments I got.

Sub TestIsEmpty()     If WorksheetFunction.CountA(Range("A38:P38")) = 0 Then         MsgBox "Empty"     Else         MsgBox "Not Empty"     End If End Sub 
like image 105
Kano Avatar answered Sep 27 '22 02:09

Kano