If then else, or select case is giving me a problem

J

jersiq

I have a Macro that dependent on a value in a cell of the worksheet,
SHOULD perform, but it isn't.
Based upon the value of cell H2, I need the macro to treat the data
manipulation in my code differently. The cutoff is 1. If the cell
value is one I need to treat the data one way, and any integer greater
than 1 needs to be treated differently.

If the value is greater than one, I have a For Each loop running which
serves as a counter for a dynamic array of integers. Whenever I run
the macro, and I get to the case of values Greater than 1, the initial
counter works (Values of 1 for the counter, not the cell the case is
evaluated). However, it never executes the second, third...nth
iteration of the values in the array. It just ends

I do know that the code for the actual manipulation works, as I have
run each of them in independent modules, and it performs as expected.
I have tried both "If Then Else" and "Select Case" and both loops give
me the same problem. Below is the code, with the actual manipulation
removed as I know it works. I have put a breakpoint in the code, and
stepped through it with the Locals Window open, and the counter never
advances past 1 for my second case, although it should.

Select Case Sheets("Sheet1").Range("H2").Value
Case Is = 1

Sheets.Add.Name = "F" & single_carrier
......More Code Here

Case Is > 1

For Each carrier In Sheets("Sheet1").Range("D2:D" &
carrier_array_upper)
'THIS IS WHERE THE COUNTER INITS AND SHOULD ITERATE
Sheets.Add.Name = "F" & carrier
Next carrier
End Select
 
J

Joel

Case doesn't havve "IS" or ">". try this

Select Case Sheets("Sheet1").Range("H2").Value
Case 1

Sheets.Add.Name = "F" & single_carrier
......More Code Here

Case Else

For Each carrier In Sheets("Sheet1").Range("D2:D" &
carrier_array_upper)
'THIS IS WHERE THE COUNTER INITS AND SHOULD ITERATE
Sheets.Add.Name = "F" & carrier
Next carrier
End Select
 
B

Bob Phillips

Of course it does

Dim var As Variant

var = 23

Select Case var

Case Is > 7: MsgBox ">10"
End Select


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top