Clear content below row A VBA

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello, I am trying to find a way to use VBA to clear all cells below row 1 on an excel worksheet.
Row A has headers I want to keep but would like vba code that I can put into a button to clear all cells under row 1, so clear rows 2,3,4, etc.. Also the sheet is called "User Info". So would like to see i could incorporate that

Tried using this but it is clearing the whole worksheet
first book is the workbook i dim


VBA Code:
 firstbook.Worksheets("User Info").Cells.clear
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Assuming that you have set 'main' appropriately, test this.

VBA Code:
main.Worksheets("User Info").UsedRange.Offset(1).Clear
 
Upvote 0
I am getting a run time error 1004
clear method of range class failed

at the main.worksheets part

VBA Code:
Sub test()

Dim main As Workbook
Set main = Application.ThisWorkbook

main.Worksheets("User Info").UsedRange.Offset(1).clear


End Sub
 
Upvote 0
This is similar to how the page is laid out with the row of header is the one i want to keep then everything end to be cleared and the header is on row 1 goes from A to row IN, if that helps too
HeaderHeaderHeaderHeaderHeaderHeader
value 1value 2value 3value 4value 5value 6
name 1name 2name 3name 4name 5 name 6
 
Upvote 0
The code worked fine for me with that set-up.
There must be something different about your worksheet.

To test, start a completely fresh workbook, name a sheet 'User Info', put some dummy data into each of the 4 cells A1:B2
Put the code into that workbook and run it. See what happens.
 
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,803
Members
449,127
Latest member
Cyko

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