VBA ir tukšs - Kā izmantot VBA IsEmpty funkciju? (Piemēri)

Satura rādītājs

IsEmpty ir darblapas funkcija, ko izmanto, lai uzzinātu, vai norādītā šūnas atsauce vai šūnu diapazons ir tukšs, jo tā ir darblapas funkcija, tāpēc, lai to izmantotu VBA, mēs izmantojam lietojumprogrammu. Darblapu metode VBA, lai izmantotu šo funkciju, šī funkcija ietilpst funkciju loģiskajos sarakstos un atgriež vērtību true, ja atsauce ir tukša.

VBA IsEtpty funkcija

VBA IsEmpty ir loģiska funkcija, kas pārbauda, ​​vai atlasītā vieta ir tukša vai nē. Tā kā tā ir loģiska funkcija, tā atgriezīs rezultātus Būla vērtībās, ti, TRUE vai FALSE.

Ja atlasītā šūna ir tukša, tā atgriezīs vērtību TRUE vai arī FALSE.

Šajā rakstā mēs parādīsim, kā izmantot funkciju “ISEMPTY” VBA, lai pārbaudītu šūnas, izmantojot VBA kodus.

Ko VEM veic ISEMPTY funkcija?

Bieži vien tukšās šūnas mūs izjauc, lai darblapā darbotos efektīvi. Tukšo šūnu atrašana nav visgrūtāk, bet, ja tukšās šūnas slēpj tās datu vidū, to atrašana prasa maksu.

Lai atrastu Excel tukšās šūnas, mums darblapas funkcija ir funkcija ar nosaukumu “ISBLANK”, bet VBA - ISEMPTY.

Tas darbojas līdzīgi kā darblapas funkcija “ISBLANK”. Tagad ieskatieties zemāk esošajā funkcijas “ISEMPTY” formulā.

Kā redzams iepriekš redzamajā attēlā, rezultāts tiek atgriezts kā Būla, ti, TRUE vai FALSE.

Funkcijas ISEMPTY piemēri VBA

Šie ir IsEmpty piemēri VBA.

1. piemērs

Tagad mēs redzēsim pirmo “ISEMPTY” praktisko piemēru. Lai to izdarītu, ieskatieties zemāk redzamajā darblapas attēlā.

Tagad, lai pārbaudītu šos visus, mēs izmantosim excel VBA ISEMPTY funkciju.

1. darbība: definējiet mainīgo kā Būla vērtību .

Kods:

Sub IsEmpty_Example1 () Dim K kā Būla beigu apakšdaļa

2. solis: šim mainīgajam piešķiriet vērtību, izmantojot funkciju VBA ISEMPTY .

Kods:

Sub IsEmpty_Example1 () Dim K kā Būla K = IsEmpty (End Sub

3. solis: izteiksme nav nekas cits kā tā, kuru mēs pārbaudām. Tagad mēs pārbaudām šūnas A1 šūnu .

Kods:

Sub IsEmpty_Example1 () Dim K kā Būla K = IsEmpty (Range ("A1"). Value) Beigas Sub

4. darbība: parādiet šī mainīgā vērtību VBA Msgbox .

Kods:

Sub IsEmpty_Example1 () Dim K Kā Būla K = IsEmpty (Range ("A1"). Vērtība) MsgBox K End Sub

Palaidiet šo kodu, lai pārbaudītu rezultātu.

Tā kā šūnā A1 ir vērtība, rezultāts tika iegūts kā FALSE.

Tagad es mainīšu šūnu atsauci no A1 uz A5.

Kods:

Sub IsEmpty_Example1 () Dim K As Būla K = IsEmpty (Range ("A5"). Vērtība) MsgBox K End Sub

Palaidiet šo kodu, lai redzētu rezultātu.

Rezultāts tika iegūts kā PATIESA, atsauces šūna A5 faktiski ir tukša šūna, tāpēc rezultāts tika iegūts kā “PATIESA”.

Tagad es pārbaudīšu šūnu A8.

Kods:

Sub IsEmpty_Example1 () Dim K Kā Būla K = IsEmpty (Range ("A8"). Vērtība) MsgBox K End Sub

Palaidiet šo kodu, lai redzētu rezultātu.

Ak !!! Uzgaidi…

Rezultāts tika iegūts kā FALSE, lai gan šūnā A8 nav vērtības.

Tagad jautājums ir par kļūdu, kas izriet no formulas “ISEMPTY”?

Nē … Pilnīgi Nē !!!

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

Mums ir alternatīva funkcijai ISEMPTY, nepiemērojot Excel VBA ISEMPTY funkciju, mēs faktiski varam pārbaudīt šūnu.

Piemēram, apskatiet zemāk esošo kodu.

Kods:

Sub IsEmpty_Example3 () Ja diapazons ("B2"). Vērtība = "" Tad diapazons ("C2"). Vērtība = "Nav atjauninājumu" cits diapazons ("C2"). Vērtība = "Savāktie atjauninājumi" Beidzas, ja beidzas apakšdaļa

Kodu rinda Range (“B2 ″). Vērtība =” nozīmē, vai šūnas B2 šūna ir vienāda ar tukšu vai nē.

Double Quotes (“”) apzīmē tukšu šūnu vai nē, ja tukšais rezultāts ir PATIESA vai FALSE.

Interesanti raksti...