Search code examples
arraysexcelvbavariant

VBA check if whole row of multidimensional variant is empty without loops


Is there a quick way to check whether a whole row of a variant is empty?

My multi-dimensional array / variant has n-rows and m-columns.

The only way I can think of is to loop through the columns (of a specific row) and use the IsEmpty() function to determine if a cell is empty.

The variant only consists strings.

Do you know a faster way? Maybe something like this pseudo-code: IsEmpty(myarr(1,*))

this pseudocode would mean to check the all columns of the first row if they are empty.


Solution

  • You could try something like:

    Sub Test()
    
    Dim myarr() As Variant, indx As Long
    
    myarr = Range("A8:C20").Value 'Or however you initialize your array.
    indx = 1 'Or whichever row you would want to check.
    
    With Application
        Debug.Print Join(.Index(myarr, indx, 0), "") <> ""
    End With
    
    End Sub
    

    Not sure if it will be faster than a loop though, since we call a worksheet application.