VBA to clear multiple cells

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
My in-expertise at VBA seems to have caught up with me. As I tried to edit this, it seems all I've done is make it do nothing...:eeek:

Here's my code:

Code:
Sub clear()    Dim objColorStop As ColorStop
    Dim mySelect As Range
    Dim myOthershtRng As Range




    Set mySelect = ActiveSheet.Range(Selection.Address)
    Set myOthershtRng = Sheets("Scheduler").Range(Selection.Address).Offset(-85, -2)
Application.ScreenUpdating = False
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
Sheets("RO").Visible = True
Sheets("RO").Select
With myOthershtRng.ClearContents
End With
Sheets("Scheduler").Select
Application.ScreenUpdating = True
'Sheets("RO").Visible = False
Sheets("Scheduler").Select
Range("R1").Select
'Call RTO
End Sub

What the code should do:
Is clear the currently selected cells, then clear the matching cells on the "RO" sheet. The cells are offset (-85,-2)
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this:
Code:
Sub Clear_Selection()
Selection.ClearContents
Sheets("RO").Range(Selection.Address).ClearContents
End Sub
 
Upvote 0
You said:
What the code should do:
Is clear the currently selected cells, then clear the matching cells on the "RO" sheet.

Why do you need :
Offset(-85, -2)
 
Upvote 0
Because the cells do identically match up. If I clear cells E89:F89 on the current sheet, then on "RO" I would need C4:D4 cleared.
 
Upvote 0
Try this:
Code:
Sub Clear_Selection()
Selection.ClearContents
Sheets("RO").Range(Selection.Address).Offset(-85, -2).ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,708
Members
453,748
Latest member
akhtarf3

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