how to check if an array is empty

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello All,

I have a global array i'm using across multiple modules. The issue is that I want to add in a coding to check to see if the array is empty then it need to call out the module that i'm using to fill in the array, otherwise if the array is not empty then it moves on with the rest of the module. The current name of the array is EXA().

Thank you.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
How about this?
VBA Code:
If Len(Join(EXA)) then msgbox "EXA is not empty"
 
Upvote 0
What type of array is it?
 
Upvote 0
I'm not sure how you call it but the array is formed using the following code:

VBA Code:
lrowMain = MAINws.Cells(Rows.Count, "C").End(xlUp).Row

EXA = MAINws.Range("C2:C" & lrowMain).Value

For Cnt = 1 To UBound(EXA)
    Select Case Len(EXA(Cnt, 1))
        Case 10
            EXA(Cnt, 1) = "0" & CStr(LCase(EXA(Cnt, 1)))
        Case 9
            EXA(Cnt, 1) = "00" & CStr(LCase(EXA(Cnt, 1)))
    End Select
Next Cnt

So that is how i fill in the array so i just need to make sure that when it being references in the future that there is information in the array and not empty.
 
Upvote 0
Ok, how about something like
VBA Code:
Dim x As Long
On Error Resume Next
x = UBound(EXA)
On Error GoTo 0
If x = 0 Then Exit Sub
 
Upvote 0
Is this correct... you are running the code you showed and then later on in the same procedure you are checking to see if any data actually went into the array, correct? If so, can't you just check the first cell that goes into the array and see if it is empty or not? If it is not empty, then the array has data.
 
Upvote 0
This should probably work too

VBA Code:
If IsEmpty(EXA) Then MsgBox "EXA is empty"
 
Upvote 0
@JEC that will return False even if there is nothing in the array.
 
Upvote 0
Ah yes, I tested with currentregion, which could have an empty array as output.
 
Upvote 0
Then like this

VBA Code:
If Len(Trim(Join(Application.Transpose(EXA)))) = 0 Then MsgBox "EXA is empty"
 
Upvote 0

Forum statistics

Threads
1,203,402
Messages
6,055,185
Members
444,768
Latest member
EMGVT

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