VBA Code for deleting empty rows at the end of a sheet

Mary Bizmax

New Member
Joined
Aug 12, 2018
Messages
4
I'm very new to macros, so please excuse my ignorance.

My workbook contains the following sheets:
"XeroImport" - a report from Xero accounting software exported to excel is pasted in there by the user (so the size varies each month)
"Pivot" which has a pivot table sourced from "XeroImport" which automatically refreshes (I've managed to code that in a macro) and then I've filtered the table to exclude blanks and the same macro copies the data into a new sheet called:
"InputSheet". My problem is that I have specified the table range to copy to be A1:H100 (because the pivot table size will vary each month) and so I end up with a lot of empty rows at the end of the "InputSheet". (eg from row 10 to row 100 this month) So when I try and use this sheet as an import to another cloud system, I'm getting a lot of error messages....so I really need to delete these rows.
Please could someone help either with VBA code to delete these empty rows at the end of the sheet? Probably a very simple question but I've been doing a lot of searching on various forums and nothing I've tried seems to work.
Many thanks.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Re: VBA Code for deleting empty rows at the end of a sheet please

.
The following macro will delete all empty rows in the range A1:G25. The range can be change as needed.

After deleting the empty row, it moves the remainder rows below up.

The sheet name can be edited as well.

Code:
Option Explicit


Sub DeleteBlankRows()


Dim i As Integer
Dim Rng As Range
Dim WorkRng As Range
Dim xRows As Long
'On Error Resume Next


Set WorkRng = Sheets("Sheet2").Range("A1:G25")


xRows = WorkRng.Rows.Count
Application.ScreenUpdating = False


For i = xRows To 1 Step -1
    If Application.WorksheetFunction.CountA(WorkRng.Rows(i)) = 0 Then
        WorkRng.Rows(i).EntireRow.Delete XlDeleteShiftDirection.xlShiftUp
    End If
Next


Application.ScreenUpdating = True
End Sub
 
Upvote 0
Re: VBA Code for deleting empty rows at the end of a sheet please

Thank you so much, works beautifully.
Very happy :)
 
Upvote 0
Re: VBA Code for deleting empty rows at the end of a sheet please

You are welcome. Glad to help.
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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