Macro to delete text from "Notes from Statements" to last row containing Data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have tried to write code to clear data in Col A from text "Notes from Statements" to last row containing Data


However, it is clearing text above NOTES TO STATEMENTS


It would be appreciated if someone could amend my code


Code:
 Sub ClearNotes()

 Dim fr As Long, lr As Long
fr = ActiveSheet.Range("A:a").Find("*" & "NOTES TO STATEMENTS*").Row
lr = Cells.Find("*", , , , xlByRows, xlPrevious).Row
    Range(Cells(fr, 1), Cells(lr, 1)).EntireRow.Delete
    
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try it like
VBA Code:
fr = ActiveSheet.Range("A:a").Find("NOTES TO STATEMENTS", , , xlPart).Row
 
Upvote 0
Solution
Thanks for the help Fluff

When running the macro, I get "Object variable or With block variable not set"

I have highlighted the item in Yellow where the rows are to be deleted i.e from "Notes to Statements" up to the last row containing data

Please see link below for workbook sample data

Kindly test and amend code

 
Upvote 0
You get the error because there are no rows that contain "NOTES TO STATEMENTS"
 
Upvote 0
Thanks for pointing this out. Code now runs smoothly
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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