Deleting Headers on Multiple Worksheets

J7House1984

New Member
Joined
Oct 30, 2020
Messages
21
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

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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
 
Upvote 0
Solution
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.
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,913
Members
448,532
Latest member
9Kimo3

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