Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Why won't this work?

Hello. I'm sure this a pretty dumb question, but any ideas why this
won't work??

Set clrarray = Sheets(Array("Forecast", "LMU", "Kit", "SMLC", "WLG",
"SMLC Cab", "Serv Cab", "Ntwk Kit", _
"TDAX", "EMS", "SCOUT", "Dir Coup"))

ActiveWorkbook.Worksheets(clrarray).Range("A5:EC50 0").ClearContents

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Why won't this work?

TRy

For Each sh In ActiveWorkbook.Worksheets(clrarray)
sh.Range("A5:EC500").ClearContents
Next sh


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Steph" wrote in message
om...
Hello. I'm sure this a pretty dumb question, but any ideas why this
won't work??

Set clrarray = Sheets(Array("Forecast", "LMU", "Kit", "SMLC", "WLG",
"SMLC Cab", "Serv Cab", "Ntwk Kit", _
"TDAX", "EMS", "SCOUT", "Dir Coup"))

ActiveWorkbook.Worksheets(clrarray).Range("A5:EC50 0").ClearContents

Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Why won't this work?

Hi
try something like the following:
Sub foo()
Dim sh_array As Variant
Dim wks As Worksheet
Dim i
sh_array = Array("sheet1", "sheet2")
For i = 0 To UBound(sh_array)
Set wks = Worksheets(CStr(sh_array(i)))
wks.range("A5:EC500").clearcontents
'MsgBox wks.Name
Next
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

"Steph" schrieb im Newsbeitrag
om...
Hello. I'm sure this a pretty dumb question, but any ideas why this
won't work??

Set clrarray = Sheets(Array("Forecast", "LMU", "Kit", "SMLC", "WLG",
"SMLC Cab", "Serv Cab", "Ntwk Kit", _
"TDAX", "EMS", "SCOUT", "Dir Coup"))

ActiveWorkbook.Worksheets(clrarray).Range("A5:EC50 0").ClearContents

Thanks!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Why won't this work?

There are two problems with the code.

First, you are setting ClrArray to a collection of sheets. Then, you
are trying to use this collection of *objects* as indices to the
Worksheets collection. That cannot work because the Worksheets
collection can be indexed only by integers or strings (and not
objects).

You should use

'Set ClrArray = ActiveWorkbook.Sheets(Array("Forecast", _
"LMU", "Kit", "SMLC", "WLG", _
"SMLC Cab", "Serv Cab", "Ntwk Kit", _
"TDAX", "EMS", "SCOUT", "Dir Coup"))
ClrArray = Array("Sheet1", "Sheet2", "Sheet3")
ActiveWorkbook.Sheets(ClrArray).Select

In the above example, your statment has been commented out. My test
used just three worksheets. Note that in my case, clrarray contains
*string* values not worksheet objects.

However, that still leaves the 2nd problem. XL's handling of 3D ranges
is something I would describe as a layer slapped on over the existing
object model. Since it doesn't quite fit in with the OM, you have to
rely on the 'selection' to make things happen. The code below works.
Note that, once again, the correct clrarray statement for you exists
only as a comment.

Option Explicit

Option Explicit

Sub testIt()
Dim ClrArray
'ClrArray = Array("Forecast", _
"LMU", "Kit", "SMLC", "WLG", _
"SMLC Cab", "Serv Cab", "Ntwk Kit", _
"TDAX", "EMS", "SCOUT", "Dir Coup")
ClrArray = Array("Sheet1", "Sheet2", "Sheet3")
ActiveWorkbook.Sheets(ClrArray).Select
Sheets(ClrArray(LBound(ClrArray))).Activate
Range("A5:EC500").Select
Selection.ClearContents
End Sub



--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hello. I'm sure this a pretty dumb question, but any ideas why this
won't work??

Set clrarray = Sheets(Array("Forecast", "LMU", "Kit", "SMLC", "WLG",
"SMLC Cab", "Serv Cab", "Ntwk Kit", _
"TDAX", "EMS", "SCOUT", "Dir Coup"))

ActiveWorkbook.Worksheets(clrarray).Range("A5:EC50 0").ClearContents

Thanks!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to update a column in a work based on another work sheet WickerMan New Users to Excel 1 December 4th 09 12:58 PM
how can i automatically generate work order numbers from work orde rob h Excel Discussion (Misc queries) 1 July 13th 09 07:59 PM
flash object dont work in my excel work sheet Nitn Excel Discussion (Misc queries) 0 July 4th 09 08:00 AM
Counting dates in multiple work sheets and work books Savage Excel Discussion (Misc queries) 0 December 19th 05 11:41 PM
Is there away to keep "auto save" from jumping to the first work sheet in the work book? Marc New Users to Excel 2 April 21st 05 01:27 AM


All times are GMT +1. The time now is 10:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"