IsEmpty är en kalkylfunktion som används för att ta reda på om en given cellreferens eller ett cellintervall är tomt eller inte eftersom det är en kalkylfunktion så att använda den i VBA använder vi Application. Kalkylbladsmetod i VBA för att använda den här funktionen, denna funktion kommer under de logiska funktionslistorna och returnerar true om referensen är tom.
VBA är tom funktion
VBA IsEmpty är en logisk funktion som testar om vald är tom eller inte. Eftersom det är en logisk funktion kommer den att returnera resultaten i booleska värden, dvs antingen SANT eller FALSKT.
Om den valda cellen är tom kommer den att returnera SANT eller annars returnerar den FALSE.
I den här artikeln visar vi dig hur du använder “ISEMPTY” -funktionen i VBA för att kontrollera cellerna med hjälp av VBA-koder.

Vad gör ISEMPTY-funktionen i VBA?
Ofta frustrerar tomma celler oss att arbeta effektivt i kalkylbladet. Att hitta de tomma cellerna är inte det svåraste, men om tomma celler gömmer dem mitt i datan, tar det en vägtull att hitta dem.
För att hitta de tomma cellerna i excel har vi funktionen ”ISBLANK” som kalkylfunktion men i VBA kallas den ”ISEMPTY”.
Detta fungerar på samma sätt som kalkylfunktionen ”ISBLANK”. Titta nu på formeln nedan för "ISEMPTY" -funktionen.

Som vi kan se i bilden ovan returnerar den resultatet som booleskt, dvs. SANT eller FALSKT.
Exempel på ISEMPTY-funktion i VBA
Följande är exempel på IsEmpty i VBA.
Exempel 1
Nu kommer vi att se det första praktiska exemplet på "ISEMPTY". För detta, ta en titt på bilden nedan i kalkylbladet.

Nu kommer vi att använda excel VBA ISEMPTY-funktionen för att testa alla dessa.
Steg 1: Definiera variabeln som Boolean .
Koda:
Sub IsEmpty_Example1 () Dim K Som Boolean End Sub

Steg 2: För denna variabel tilldela värdet genom VBA ISEMPTY- funktionen.
Koda:
Sub IsEmpty_Example1 () Dim K As Boolean K = IsEmpty (End Sub

Steg 3: Uttryck är inget annat än vilken cell vi testar. Nu testar vi cell A1-cell .
Koda:
Sub IsEmpty_Example1 () Dim K As Boolean K = IsEmpty (Range ("A1"). Value) End Sub

Steg 4: Visa värdet på denna variabel i VBA Msgbox .
Koda:
Sub IsEmpty_Example1 () Dim K As Boolean K = IsEmpty (Range ("A1"). Value) MsgBox K End Sub

Kör den här koden för att kontrollera resultatet.

Eftersom det finns ett värde i cellen A1 fick vi resultatet som FALSE.
Nu kommer jag att ändra cellreferensen från A1 till A5.
Koda:
Sub IsEmpty_Example1 () Dim K As Boolean K = IsEmpty (Range ("A5"). Value) MsgBox K End Sub
Kör den här koden för att se resultatet.

Vi fick resultatet som SANT den refererade cellen A5 är faktiskt tom cell så vi fick resultatet som “SANT”.
Nu ska jag testa cellen A8.
Koda:
Sub IsEmpty_Example1 () Dim K As Boolean K = IsEmpty (Range ("A8"). Value) MsgBox K End Sub
Kör den här koden för att se resultatet.

Åh!!! Vänta…
Vi fick resultatet som FALSE trots att det inte finns något värde i cellen A8.
Nu är frågan ett felresultat från formeln "ISEMPTY" ?.
Nej … absolut nej !!!
When I tried examining the cell A8 actually there is a space character inside the cell which is not easy to see with bare eyes.

So the conclusion is even Space is considered as a character in excel and VBA language.
Example #2 - Combination of VBA ISEMPTY with IF Condition
Actually, the real usage of the function “ISEMPTY” is admirable when we use it with other logical functions.
Especially when we use it with IF condition we can derive many useful results from it.

For this demonstration take a look at the below example.
In the Status column, if the “PF Status” column is empty, we need the value as “No Update,” and if there is any value, we need the values as “Collected Updates.”
Remember here we don’t need the default result of TRUE or FALSE. We need our own results here, to have our own results we need to use Excel VBA ISEMPTY with IF condition.
Step 1: Open IF condition.
Code:
Sub IsEmpty_Example2() If End Sub

Step 2: Inside the IF condition open ISEMPTY function.
Code:
Sub IsEmpty_Example2() If IsEmpty( End Sub

Step 3: The first logical test is cell B2 value is empty or not.
Code:
Sub IsEmpty_Example2() If IsEmpty(Range("B2").Value) Then End Sub

Step 4: If the logical test in excel vba is TRUE i.e., if the cell is empty, we need the result as “No Update” in cell C2.
Code:
Sub IsEmpty_Example2() If IsEmpty(Range("B2").Value) Then Range("C2").Value = "No Update" End Sub

Step 5: If the logical test is FALSE, we need the result in cell C2 as “Collected Updates.”
Code:
Sub IsEmpty_Example2() If IsEmpty(Range("B2").Value) Then Range("C2").Value = "No Update" Else Range("C2").Value = "Collects Updates" End If End Sub
Ok, we are done.
Run the code to get the result.

We got the result as “Collected Updates” because we have the non-empty cell in B2.
Now similarly apply the code for other cells to test.
Code:
Sub IsEmpty_Example2() If IsEmpty(Range("B2").Value) Then Range("C2").Value = "No Update" Else Range("C2").Value = "Collects Updates" End If If IsEmpty(Range("B3").Value) Then Range("C3").Value = "No Update" Else Range("C3").Value = "Collected Updates" End If If IsEmpty(Range("B4").Value) Then Range("C4").Value = "No Update" Else Range("C4").Value = "Collected Updates" End If End Sub

Run this code to have the results.

In cell C3 we got the result as “No Update” because there is no value in cell B3 i.e. Empty Cell. Since the logical formula returned TRUE we got the respective result.
Example #3 - Alternative to VBA ISEMPTY Function
Vi har ett alternativ till ISEMPTY-funktion, utan att använda excel VBA ISEMPTY-funktionen kan vi faktiskt testa cellen.
För ett exempel, se nedanstående kod.
Koda:
Sub IsEmpty_Example3 () If Range ("B2"). Value = "" Then Range ("C2"). Value = "No Update" Else Range ("C2"). Value = "Collected Updates" End If End Sub
Raden med kodintervall (“B2 ″). Värde =” ” betyder om cellen B2-cellen är lika med tom eller inte.
Dubbla citat (“”) representerar en tom cell eller inte om det tomma resultatet är SANT eller annars FALSKT.