ssblue
asked on
Excel - click on a cell and have everything in another cell clear
I would like to click on ' J1 ' / or a button and have everything in H2:H500 be deleted
Place this in Sheet1's code.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("J1")) Is Nothing Then
Range("H2:H500").ClearContents
End If
End Sub
ASKER
I'm getting reference not valid. My sheet name is ' Calculations ' ???? I've never done this so please be specific.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can record a Macro to do that very easy.
ASKER
Still getting error - see attachment
test.xlsx
test.xlsx
I've attached a sample workbook. When it's open type Alt+F11or click the "Visual Basic" button under "File" to get to Visual Basic. Then in the Project-VBA Project window select "Sheet1(Calculations)"
29002867.xlsm
29002867.xlsm
test this, clikc the button
test.xlsm
test.xlsm
Right Click on that button and view code and paste below code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = Worksheets("Calculations")
ws.Range("H2:H500").ClearContents
End Sub
since the button is on sheet Calculations, you only need this line
Range("H2:H500").ClearCont ents
Range("H2:H500").ClearCont
ASKER
Thanks for all the suggestions.
However, just for the record, as a novice more explicit directions would have prevented some of the confusion and need for all the extra suggestions.
I granted points based on my original question and the first response that works, even though it took awhile for me to understand what was needed to make it work.
Thanks again to everyone.
However, just for the record, as a novice more explicit directions would have prevented some of the confusion and need for all the extra suggestions.
I granted points based on my original question and the first response that works, even though it took awhile for me to understand what was needed to make it work.
Thanks again to everyone.
You are most Welcome.
sheets(1).Range("H2:H500")