Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Clear Macro I recorded a macro so that it clears certain cells within my excel s

ID: 3560797 • Letter: C

Question

Clear Macro

I recorded a macro so that it clears certain cells within my excel sheet, but the problem is that i want the macro to run from another sheet but clears contents from another.

Let's say I am on sheet 1 but and i want to clear contents on sheet 2.

The ranges i want to clear is from B9:H9 xl down, to the last row I have filled with contents. So for example the last row I have filled with contents is row 16 so when i run the macro button is clear from B9:H9 to B16:H16 anything also between them are cleared also.

Thanks

Explanation / Answer

%T7ry it like this:;'

Sub clear_me()
Dim lastrow As Long
lastrow = Sheets("Sheet2").Columns("B:H").Find(What:="*", After:=[B1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
If lastrow >= 9 Then
Sheets("Sheet2").Range("B9:H" & lastrow).ClearContents
End If
End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote