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

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
260
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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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