Deleting Headers on Multiple Worksheets

J7House1984

New Member
Joined
Oct 30, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
I am trying to delete the contents on everything but the certain rows in 2 different Worksheets. Below is the VBA I wrote to attempt to accomplish this task but it did not go according to plan.

The first script did what I wanted it to and so I thought I would repeat the script and adjust it to the next worksheet. When I ran the script it removed everything on the entire worksheet. What did I do? How can I make this work properly?

I want to delete all content except for the headers in Row 1 of the IQData worksheet and then I want to delete all content below the the headers in the UploadTemplate worksheet after Row 7. (See screenshot for reference)

VBA Code:
Sub ClearContents()

With ThisWorkbook.Worksheets("IQData")
Range(.Range("A2"), .UsedRange.Offset(1, 0)).EntireRow.Delete
End With

With ThisWorkbook.Worksheets("UploadTemplate")
Range(.Range("A8"), .UsedRange.Offset(1, 0)).EntireRow.Delete
End With

End Sub
 

Attachments

  • Deleting Content Issue.png
    Deleting Content Issue.png
    13.2 KB · Views: 2

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,410
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Maybe:
VBA Code:
Sub ClearContents()

With ThisWorkbook.Worksheets("IQData")
    Range(.Range("A2"), .UsedRange.Offset(1, 0)).EntireRow.Delete
End With

With ThisWorkbook.Worksheets("UploadTemplate")
    .UsedRange.Offset(7, 0).EntireRow.Delete
End With

End Sub
 
Solution

J7House1984

New Member
Joined
Oct 30, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Maybe:
VBA Code:
Sub ClearContents()

With ThisWorkbook.Worksheets("IQData")
    Range(.Range("A2"), .UsedRange.Offset(1, 0)).EntireRow.Delete
End With

With ThisWorkbook.Worksheets("UploadTemplate")
    .UsedRange.Offset(7, 0).EntireRow.Delete
End With

End Sub
Thanks, that worked beautifully. I also realized what I forgot to do thank you for your help.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,957
Messages
5,621,823
Members
415,859
Latest member
Vain

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
Top