Select case not stepping into matching case

cbrf23

Board Regular
Joined
Jun 20, 2011
Messages
241
Hi, I'm trying to use select case to perform a specific set of actions based on an integer I pass when calling this class method.

The subroutine I'm trying to run passes 3 for the argument "Offsets".
When I check my immediates window ?Offsets returns 3. So I know this is working. The range "rngTarget" is also being passed properly.

But for some reason, when I step through the code manually, even though Offsets = 3, it never steps into that case. It just steps past all of them as if they are false.

I dont get any kind of error message, it just never steps into the case.

I dont understand this...what did I do wrong here?

Code in sub calling method and passing arguments:
Code:
        BPFeature.Output rngOutput, 3
Code in class ClaFeature that is not working correctly:
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Output(rngTarget As Range, Offsets As Integer)
'''''''''''''''''''''''''
Dim lngTarget                   As Long
'''''''''''''''''''''''''
lngTarget = rngTarget.Rows.Row
Set rngTarget = Range("A" & lngTarget)
'''''''''''''''''''''''''
Select Case Offsets
'''''''''''''''''''''''''
Case Offsets = 1
       With rngTarget
            .Value = Me.Item
            .Offset(0, 1).Value = Me.Description
        End With
'''''''''''''''''''''''''
Case Offsets = 2
       With rngTarget
            .Value = Me.Item
            .Offset(0, 1).Value = Me.Description
            .Offset(0, 2).Value = Me.Method
        End With
'''''''''''''''''''''''''
Case Offsets = 3
       With rngTarget
            .Value = Me.Item
            .Offset(0, 1).Value = Me.Description
            .Offset(0, 2).Value = Me.Method
            .Offset(0, 3).Value = Me.Zone
        End With
'''''''''''''''''''''''''
End Select
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
On each case line, remove the offsets = xx
Rich (BB code):
Select Case Offsets <- This line has already instructed Select to look at the value of Offsets
'''''''''''''''''''''''''
Case Offsets = 1 <- this line is now treating offsets = 1 as a True or False Expression



Try just like this
Rich (BB code):
Select Case Offsets
'''''''''''''''''''''''''
Case 1
    'do something
Case 2
    'do something
 
etc..

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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