I have a 55,000 row single-column spreadsheet containing text (sample attached). The basic format is a heading row (in bold, green, underlined text) followed by one or more rows (single cells in column A) of text under that heading, followed by the next heading, and rows of text, etc. I am editing this spreadsheet to clear and then delete some of these headings along with the rows of text that follow it. Prior to running the VBA code that I am having trouble creating, I will have replaced the heading rows that need to be deleted with the word "DELETE".
I first worked on the code that is set off in the middle below that allows me to select a cell marked "DELETE" and then run the macro to clear it and the lines below it down to the next heading. That seems to work, but given the size of the spreadsheet I would like to automate this. Any help would be appreciated. (sorry code below is not formatted properly, I don't know how to do it)
Alan
Sub DeletionMacro() Dim oRange As Range, aCell As Range Dim ws As Worksheet Dim SearchString As String On Error GoTo What Set ws = Worksheets("Sheet1") Set oRange = ws.Columns(1) SearchString = "DELETE" Set aCell = oRange.Find(What:=SearchString, LookIn:=xlValues, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=True, SearchFormat:=False) If Not aCell Is Nothing Then Set stcell = ActiveCell Application.FindFormat.Clear With Application.FindFormat.Font .Name = "Arial" .FontStyle = "Bold" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .Underline = xlUnderlineStyleSingle .Color = 26112 .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With Cells.Find(What:="?", After:=ActiveCell, LookIn:=xlValues, LookAt:= _ xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=True).Activate ActiveCell.Offset(-1, 0).Select Set rg = Range(ActiveCell, stcell) rg.Select Selection.Clear Application.FindFormat.Clear End If Do Until aCell Is Nothing Set aCell = oRange.FindNext(After:=aCell) Loop What: MsgBox Err.Description End Sub
Book2.xlsx