VBA loop through array but skipping blank cells

  • I have a single column array I'm spinning through to retrieve data, but I have to skip every 4th cell, which is empty. There is the possibility that a user could put a note or something in those cells, so I cant absolutely count on them always being empty. Is there a more elegant way to skip these cells than what I have below?


    Code
    For x = 1 To y  
        
            If (x Mod 4) = 0 Then
                GoTo SkipSpace
            End If
            
            ' Get cell data...
        
    SkipSpace:
        Next


    Thanks for any ideas!

  • Re: VBA loop through array but skipping blank cells


    deal with the data rather than the loop number
    something along the lines of this

    Code
    For x = 1 To y
         
        If Cells(x, WhateverColumn).value <> "" Then
            ' Get cell data...
        End If
        
    Next
  • Re: VBA loop through array but skipping blank cells


    Thanks for the suggestion NoSparks, but I cant rely on the cells remaining empty. There will be multiple (30+) versions of this workbook, so if a user puts something in an empty cell, intentional or not, the data will be unreliable.

  • Re: VBA loop through array but skipping blank cells


    You can try something like this:

    Code
    For x = 1 to y
        If Not x / 4 = Int(x / 4) then
            'get data
        End If
    Next

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!