deleting blank rows outside used range

vba code needed:

I'm trying to delete empty or blank rows.

Here is the weird thing.

I'm copying and pasting data into this worksheet.

so a cell may contain some blank stuff.
but the row appears to be blank....

this will not delete those rows

I was gonna try and say delete any blank rows outside my usedrange, but afraid it would leave those rows..?



For x = wb.Sheets("Import Sheet").Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
      If WorksheetFunction.CountA(wb.Sheets("Import Sheet").Rows(x)) = 0 Then
         wb.Sheets("Import Sheet").Rows(x).Delete
      End If
   Next

Open in new window



Thanks
fordraiders
LVL 3
FordraidersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
You can do something like this to do what you are looking for..

    Dim i As Long

    i = 1

    Do Until i > wb.Sheets("Import Sheet").Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

        If Application.WorksheetFunction.CountA(wb.Sheets("Import Sheet").Range(i & ":" & i)) = 0 Then
            Rows(i).Delete
        Else
            i = i + 1
        End If

    Loop

Open in new window


Saurabh...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
Save the workbook as an xlsb file, close, open and save it to it's original file type.
0
Rob HensonFinance AnalystCommented:
Are you trying to get rid of the surplus beyond the used range?

You will always have 1048576 rows on a sheet whether they are used or not and cannot be deleted.

Likewise you will always have 16384 columns which cannot be reduced.

Spare rows or columns can however be hidden if so required but the file will take the hidden rows and columns into account with the used range and will make the file seem a lot bigger than it really is.

Thanks
Rob H
0
FordraidersAuthor Commented:
thanks for the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.