How to remove a block of text

sodapop

New Member
Joined
Sep 14, 2008
Messages
20
Hi,

I have report that puts this block of text after a blank line and I would like to delete it in a macro. The lines of data above are varying length IE 32 rows of data one time then 25 rows the next.

data
data
data

*My Open calls
Copyright (c) 2000-2018 salesforce.com, inc. All rights reserved.
Confidential Information - Do Not Distribute
Generated By: John Q Public 8/9/2018 8:24 PM
XZY Inc.



Thanks for the help.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
EDIT: Just saw your 2nd post. This assumes that each line of the "block" is in a separate row and the block is in col A, below all other data in col A.
Code:
Sub BeatTheBlock()
'assume block is in col A - change range to suit
Dim lR As Long, lastCell As Range, firstCell As Range
Set lastCell = Cells(Rows.Count, "A").End(xlUp)  'change column to suit
Set firstCell = lastCell.End(xlUp)
Range(firstCell, lastCell).ClearContents
End Sub
 
Last edited:
Upvote 0
Maybe this, assuming data is in col "A"

Code:
Sub MM2()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For r = lr To 5 Step -1
    If InStr(Range("A" & r).Value, "*My") Then
    Range("A" & r).Resize(5).EntireRow.Delete
    End If
Next r
End Sub
 
Upvote 0
Also assuming data is in Column A, here is one more to consider...
Code:
Sub BeatTheBlock2()
  Dim Ar As Range
  Set Ar = Columns("A").SpecialCells(xlConstants)
  Ar.Areas(Ar.Areas.Count).Clear
End Sub
 
Last edited:
Upvote 0
Thanks JoeMo it works great. I am trying to write a macro that will convert a table to a non-table format. When I do it manually it works but the macro doesn't clear the dropdown arrows. And that is the first step in cleaning up the report.


Sub sm_table_removal()
'
' sm_table_removal Macro
'

'
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$H$43"), , xlYes).Name = _
"Table1"
Range("Table1[#All]").Select
ActiveSheet.ListObjects("Table1").TableStyle = ""
Range("A3").Select
End Sub
 
Upvote 0
I am trying to write a macro that will convert a table to a non-table format.
Does this macro do what you want...
Code:
Sub ConvertTableToRange()
  Dim StartCell As Range, Data As Variant
  With ActiveSheet.ListObjects("Table1")
    Set StartCell = .Range(1)
    Data = .Range.Formula
    .Delete
    StartCell.Resize(UBound(Data, 1), UBound(Data, 2)) = Data
  End With
End Sub
 
Last edited:
Upvote 0
Hi @Rick Rothstein,

Sorry for the slow response.

The code hung up at ("Table1"). I am assuming that I need to rename Table1 to something different but I am not sure what the name should be.
 
Upvote 0
The code hung up at ("Table1"). I am assuming that I need to rename Table1 to something different but I am not sure what the name should be.
Select any cell within your table... you should get a new menu tab at the top labeled "Table Tools - Design"... select that tab if it is not automatically selected and look to the left of the ribbon... your table name should be listed there... use exactly what it says the table's name is.
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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