+ Reply to Thread
Results 1 to 5 of 5

Select Case not working

Hybrid View

  1. #1
    Registered User
    Join Date
    01-23-2009
    Location
    Hillsboro, Oregon
    MS-Off Ver
    Excel 2007
    Posts
    11

    Select Case not working

     Set GL = ActiveSheet.Range("d6:as6")
     Set SW = ActiveSheet.Range("aw6:cz6")
             
             If Process = "GL" Then
                GL.Activate
                            
                For Each Cell In Range("d6:as6")  '<--------- How do I call this properly?
                    If Cell.Value = Designation Then
                        
                        Select Case Quantity.Value  '<----- Object Required
                        
                            Case 1 To 14
                                PostCol = Cells.Column
                                
                            Case 15 To 24
                                PostCol = Cells.Offset(0, 1).Column
                                
                            Case 24 To 999
                                PostCol = Cells.Offset(0, 2).Column
                          
                        End Select
                      End If
                  Next Cell
              End If
    This is part of a function I am trying to make. I am getting an "Object Required" error. Quantity is passed from the Sub to the function o.k. (Inteli-Sense shows the value for me). Can I not use a Select Case operation this way?

    Also, when I start the loop, that is the only way I get it to recognize the range. How do I start that loop properly?

    All help is appreciated!
    Thanks!
    Last edited by RadBrad; 08-30-2009 at 04:26 PM. Reason: Added question

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Select Case not working

    What do you mean "start the loop properly"?
    For Each Cell in Range("D6:AS6")
    '...
    Next Cell
    is fine syntax.

    The variables Designation and Quantity need to be assigned values.

    Is Quantity a Range?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    01-23-2009
    Location
    Hillsboro, Oregon
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Select Case not working

    Farther up the code, designation and quantity are assigned.

    I guess what I mean by Proper is that if I am going to assign the range as cell values, would I need to set a range, like my GL and SW?

    I can see by trial and error that I do not. I was trying to define a range that I thought was changing, but is not.

    And I figured out the Select Case question. It is just Select Case Quantity without the "value" part, which makes sense, too.

    Thanks!

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Select Case not working

    Is this closer to what you want?
    Dim RangeForLooping as Range, Cell as Range
    Set RangeForLooping = Range("D6:AS6")
    
    For Each Cell in RangeForLooping.Cells
        '...
    Next Cell

  5. #5
    Registered User
    Join Date
    01-23-2009
    Location
    Hillsboro, Oregon
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Select Case not working

    Yes! That is exactly what I was looking for.

    What I am writing this module for is to post data from a daily scheduling worksheet to several different tracking sheets based on the sales streams, processes used, styles of objects, and diameters. In the future, I will have to add different styles, sales streams, and processes and I'd like to test each sheet to define the ranges needed. Before your answer, I was looking at having to adjust the module by hand as the worksheets increased in size.

    Thank you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1