PDA

View Full Version : [SOLVED:] Select Case Problem



austenr
11-17-2004, 12:36 PM
Hi ,

When I try to run the following line of code I get this error:

Runtime error ?424?

Object Required

Public Sub ClearSelectedCells()



Select Case ws.Name This is the line with the error.

What is causing the problem?

Zack Barresse
11-17-2004, 12:44 PM
Hi Austen,

It's most likely a problem with how you have declared/Set your variable 'ws'. Can you post all of the code or at least the portion where you define what 'ws' is? (I'm assuming Worksheet)

austenr
11-17-2004, 12:58 PM
Public Sub ClearSelectedCells()
Dim ws As Double
Select Case ws.Name
Case "Sheet1"
ws.Range("B5:B147", "B20:B22", "B26:B32", "B38:B45", "B49:B52", F1, "F5:F7", "F10:F11").ClearContents
'Case "Sheet2"
' ws.Range("B7:B15", B17, "B21:B36", F1, "F5:F6", "F9:F10").ClearContents
'Case "Sheet3"
' ws.Range("A9:E37", "G9:J37", "K9:L37", "E1:E2", L2).ClearContents
'Case "Sheet4"
' ws.Range("B17:B20", "B25:B28", "C4:C5", C7, "C9:C13", "C31:C36", "E17:E20", G18, "H4:H5", J15).ClearContents
End Select
End Sub

Zack Barresse
11-17-2004, 01:00 PM
Ah, ok. You have ws as Double where it needs to be an Object, usually done like ...


Dim ws As Worksheet
or

Dim ws As Object

Do you already have a loop setup to go through each sheet, or is this all of your code? (Again, assuming you want to go through each sheet.)