vba sheets(array(

EOAEvan

Active Member
Joined
Sep 20, 2007
Messages
399
The following code does not work on the sheets in the array. Instead it only works on the active sheet. Why?

Code:
Sub ClearContents()


frow = Array(9, 15, 21, 26, 35, 37, 42, 45, 50, 53, 58, 61, 64, 69, 71, 76, 80, 83, 86, 91, 94, 97, 102, 105, 108, 113, 127, 134, 138, 144, 147, 153, 156, 160, 164, 168, 173, 177, 187)
trow = Array(13, 19, 24, 32, 35, 39, 43, 46, 51, 54, 59, 62, 67, 69, 74, 78, 81, 84, 89, 92, 95, 100, 103, 106, 111, 123, 132, 136, 142, 145, 148, 154, 158, 161, 166, 170, 175, 182, 188)

For i = LBound(frow) To UBound(frow)
    With Sheets(Array("ROF Mon", "ROF Tue", "ROF Wed", "Act Thu", "Act Fri"))
    Range("D" & frow(i) & ":E" & trow(i)).ClearContents
    End With
Next i

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I think (only think) it might because WITH can only work on a single object and as such your WITH array is not understood by vba ... ofr some reason it isn't crashing but it is ignoring the statement ....

of course I am willing to be corrected

Kevin
 
Upvote 0
Maybe:
Code:
Sub ClearContents()


frow = Array(9, 15, 21, 26, 35, 37, 42, 45, 50, 53, 58, 61, 64, 69, 71, 76, 80, 83, 86, 91, 94, 97, 102, 105, 108, 113, 127, 134, 138, 144, 147, 153, 156, 160, 164, 168, 173, 177, 187)
trow = Array(13, 19, 24, 32, 35, 39, 43, 46, 51, 54, 59, 62, 67, 69, 74, 78, 81, 84, 89, 92, 95, 100, 103, 106, 111, 123, 132, 136, 142, 145, 148, 154, 158, 161, 166, 170, 175, 182, 188)

Sheets(Array("ROF Mon", "ROF Tue", "ROF Wed", "Act Thu", "Act Fri")).Select

For i = LBound(frow) To UBound(frow)
    Range("D" & frow(i) & ":E" & trow(i)).ClearContents
Next i
Sheets("ROF Mon").Select

End Sub
 
Upvote 0
Interesting... Any suggestions on how to make it work? Other than repeating the code for each sheet individually?
 
Upvote 0
Maybe:
Code:
Sub ClearContents()


frow = Array(9, 15, 21, 26, 35, 37, 42, 45, 50, 53, 58, 61, 64, 69, 71, 76, 80, 83, 86, 91, 94, 97, 102, 105, 108, 113, 127, 134, 138, 144, 147, 153, 156, 160, 164, 168, 173, 177, 187)
trow = Array(13, 19, 24, 32, 35, 39, 43, 46, 51, 54, 59, 62, 67, 69, 74, 78, 81, 84, 89, 92, 95, 100, 103, 106, 111, 123, 132, 136, 142, 145, 148, 154, 158, 161, 166, 170, 175, 182, 188)

Sheets(Array("ROF Mon", "ROF Tue", "ROF Wed", "Act Thu", "Act Fri")).Select

For i = LBound(frow) To UBound(frow)
    Range("D" & frow(i) & ":E" & trow(i)).ClearContents
Next i
Sheets("ROF Mon").Select

End Sub

This is still only performing the code on the active sheet.
 
Upvote 0
Change
Code:
 Range("D" & frow(i) & ":E" & trow(i)).ClearContents
to
Code:
 Range("D" & frow(i) & ":E" & trow(i)).Select
Selection.ClearContents
 
Upvote 0
You coudl try

For each ws in Worksheets
if ws.name = "ROF Mon" or ws.name = "ROF Tue" or ws.name = etc etc then
For i ........
Next i
next ws
 
Upvote 0

Forum statistics

Threads
1,224,536
Messages
6,179,402
Members
452,909
Latest member
VickiS

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