Consulting

Results 1 to 4 of 4

Thread: Select Case Problem

  1. #1
    VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Select Case Problem

    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?



  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    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)

  3. #3
    VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    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

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    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.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •