Using an array to chage a reference but do the same job

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
262
Office Version
  1. 2010
Platform
  1. Windows
Sub RESET()

Dim WS As Worksheet
Set WS = ThisWorkbook.Sheets("Sheet1")
WS.Range("B2").ClearContents
WS.Range("B3").ClearContents
WS.Range("A4").ClearContents
WS.Range("B4").ClearContents
WS.Range("C4").ClearContents
WS.Range("F1").ClearContents
WS.Range("F2").ClearContents

End Sub

the code above does he same job over and over I would like to build the cell reference into an array
I recorded to references and am sure there is a way to tidy up this dirty code


Adam
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try...

Code:
Sub RESET()


Dim WS As Worksheet
Set WS = ThisWorkbook.Sheets("Sheet1")
WS.Range("B2:B4,A4,C4,F1:F2").ClearContents


End Sub

Hope this helps!
 
Upvote 0
Adam

Why not use something like this?
Code:
WS.Range("A4, B2:B4, C4, F1:F2",).ClearContents
 
Upvote 0
Sure does.... I know i'm not a tidy programmer but every little bit helps :)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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