Clear a Sheet from a Workbook which is ClosedĪnd in the below code, we have referred to the “Sheet1” from the workbook “sample-file”, stored on a specific location.
This code first activates the “Sheet1” from the book and clear it. Workbooks("Book1").Sheets("Sheet1").Activate But make sure to have the workbook open at the time run this code. The below code can refer to the workbook “Book1” and clear the sheet “Sheet1”. Cells.ClearContents 'to clear contentsĬells.ClearHyperlinks 'to clear hyperlinksĬells.ClearOutline 'to clears outline Clear a Sheet from a Specific Workbook You can also use the below methods to clear different things. Helpful Links: Run a Macro – Macro Recorder – Visual Basic Editor – Personal Macro Workbook Other Things to Clear In this code, the first activates the “Sheet1” and the second line clears everything. So let’s say you want to clear the “Sheet1”, the code would be like: Sheets("Sheet1").Activate
There’s one thing that you need to note down that to clear a sheet that sheet needs to be activated. When you run this code, it will clear everything from all the cells from the active sheet, as I have already mentioned that we have used clear to refer to the entire worksheet and clear to clear it. Let’s say if you want to clear all the content from the activate sheet, the code would be like below. Sub vbaclearsheet() Dim wb As Workbook Application.ScreenUpdating False Set wb Workbooks.Open('C:UsersDellDesktopsample-file.xlsx') wb.Sheets('Sheet1').Activate Cells.Clear wb.Close SaveChanges:True Application. To clear an entire sheet using a VBA code in one go, you need to use two things, first is the CLEAR method, and then CELLS to refer to all the cells of a worksheet.