delete row after last data row

steve hill

Board Regular
Joined
Jul 11, 2006
Messages
156
Office Version
  1. 365
Platform
  1. Windows
Hi I have recorded a macro that update a query and copies four columns of formulas down beside the query table. then updates another query. what i need to do is add something that will delete all the rows after the last row of data in the first query. the total number of rows chages every time, But I have only copied the formulas down to row 1000. I have copied the code procuced by the macro below and added a comment were I need to delet the rows.

Sub updatereport()
'
' updatereport Macro
'

'
Sheets("grns").Select
Range("A1").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Range("E2:H2").Select
Selection.AutoFill Destination:=Range("E2:H1000"), Type:=xlFillDefault
Range("E2:H1019").Select
'add code to delete all row after last data on column A
Sheets("NCR").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Sheets("report").Select
Range("A1").Select
End Sub

thanks
steve
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
See added bits in red:
Rich (BB code):
Sub updatereport()
'
' updatereport Macro
 
Sheets("grns").Select
Range("A1").QueryTable.Refresh BackgroundQuery:=False
Range("E2:H2").AutoFill Destination:=Range("E2:H1000"), Type:=xlFillDefault
 
Dim i As Long
i = Range("A" & Rows.Count).End(xlUp).Row + 1
Range(Range("A" & i), Range("A" & i).End(xlDown)).EntireRow.Delete
 
Sheets("NCR").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Sheets("report").Select
Range("A1").Select
 
End Sub
 
Last edited:
Upvote 0
thanks for quick reply
I got an error
runtime 438 object doent support this property or method

the highlighted row in debubber was

Range(Range("A" & i), Range("A" & i).End(xlDown)).entirerows.Delete

Steve
 
Upvote 0
I editted my post after I replied, that line should read:
Code:
Range(Range("A" & i), Range("A" & i).End(xlDown)).EntireRow.Delete
I'd made a typo and put an 's' after row

Error: .EntireRows.Delete
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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