J7House1984
New Member
- Joined
- Oct 30, 2020
- Messages
- 21
- Office Version
- 365
- Platform
- 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)
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