Remove Array Blank Rows

JStellato

Board Regular
Joined
Nov 6, 2010
Messages
55
Hello, I'm working with an array and am new to VBA, I have this worksheet:

Excel Workbook
ABCDEFGH
1John312001John31200
2Ramone242002Ramone24200
3Ariel2503
4Baby0104
5John312001John31200
6Ramone242002Ramone24200
7John312001John31200
8Ramone242002Ramone24200
Sheet1




The code I use to take the data on the left and output it to the right is this:


For lngRow = 1 To UBound(MyArray, 1)
If MyArray(lngRow, 3) * 10 <> 2000 Then
For lngCol = 1 To UBound(MyArray, 2)
MyArray(lngRow, lngCol) = vbNullString
Next
End If
Next

.Range("E1").Resize(UBound(MyArray, 1), UBound(MyArray, 2)) = MyArray


The problem is, I don't want the blank rows in the array, I would like the code to skip them. Basically this code is all from forum members, so I'm having a hard time understanding exactly how it's working. I know I want a "if isnull" or something similar but am unsure of how to implement it.

Thanks if you can help!
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
hth

Dave

Code:
Sub Redo2()
    Dim MyArray()
    Dim lngRow As Long
    Dim lngCol As Long
    
    MyArray = Range([a1], [c8])

    For lngRow = 1 To UBound(MyArray, 1)
        If MyArray(lngRow, 3) * 10 <> 2000 Then
            For lngCol = 1 To UBound(MyArray, 2)
                MyArray(lngRow, lngCol) = vbNullString
            Next
        End If
    Next
    Columns("E:G").ClearContents
    Range("E1").Resize(UBound(MyArray, 1), UBound(MyArray, 2)) = MyArray
    On Error Resume Next
    Columns("E:G").SpecialCells(xlBlanks).Delete xlUp
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,920
Latest member
jaspers

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