ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   find last record in macro and delete all after (https://www.excelbanter.com/excel-programming/373088-find-last-record-macro-delete-all-after.html)

Sherife

find last record in macro and delete all after
 
How do I design a macro to find the last record in a report and delete each
row after. Keeping in mind that the cell reference can change to where the
last record is found??? Help please!!!

Tom Ogilvy

find last record in macro and delete all after
 
If it is the last record, then what is being deleted. If there is something
different from records, in the sheet, then how do you distinguish a record
from other data.

if the address of the last record is known (assume it is A132

lastRecordAddress = "A123"

Range(lastRecordAddress, "A65535").Offset(1,0).EntireRow.Delete

--
Regards,
Tom Ogilvy

"Sherife" wrote in message
...
How do I design a macro to find the last record in a report and delete
each
row after. Keeping in mind that the cell reference can change to where
the
last record is found??? Help please!!!




Sherife

find last record in macro and delete all after
 
Thanks for being so quick! I have to add information to an invoice so with
each invoice the last record changes and that's why I need it to find the
last record and then delete the added information after that. I add the
extra information to several cells in a column so that if more records come
in month to month that information flows down the page far enough to match
each additional record

"Tom Ogilvy" wrote:

If it is the last record, then what is being deleted. If there is something
different from records, in the sheet, then how do you distinguish a record
from other data.

if the address of the last record is known (assume it is A132

lastRecordAddress = "A123"

Range(lastRecordAddress, "A65535").Offset(1,0).EntireRow.Delete

--
Regards,
Tom Ogilvy

"Sherife" wrote in message
...
How do I design a macro to find the last record in a report and delete
each
row after. Keeping in mind that the cell reference can change to where
the
last record is found??? Help please!!!





Tom Ogilvy

find last record in macro and delete all after
 
assume the data starts in F3

Sub Cleanup()
Dim rng as range
set rng = Range("F3")
if isemtpy(rng) then exit sub
if not isblank(Range("F3").Offset(1,0)) then
set rng = rng.End(xldown))
rng.offset(1,0).Resize(100,10).Clearcontents
end if
end sub

Since your description was extremely general, adjust the above to suit your
specific situation

--
Regards,
Tom Ogilvy


"Sherife" wrote in message
...
Thanks for being so quick! I have to add information to an invoice so
with
each invoice the last record changes and that's why I need it to find the
last record and then delete the added information after that. I add the
extra information to several cells in a column so that if more records
come
in month to month that information flows down the page far enough to match
each additional record

"Tom Ogilvy" wrote:

If it is the last record, then what is being deleted. If there is
something
different from records, in the sheet, then how do you distinguish a
record
from other data.

if the address of the last record is known (assume it is A132

lastRecordAddress = "A123"

Range(lastRecordAddress, "A65535").Offset(1,0).EntireRow.Delete

--
Regards,
Tom Ogilvy

"Sherife" wrote in message
...
How do I design a macro to find the last record in a report and delete
each
row after. Keeping in mind that the cell reference can change to where
the
last record is found??? Help please!!!








All times are GMT +1. The time now is 05:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com