ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If then else, or select case is giving me a problem (https://www.excelbanter.com/excel-programming/403944-if-then-else-select-case-giving-me-problem.html)

[email protected]

If then else, or select case is giving me a problem
 
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



joel

If then else, or select case is giving me a problem
 
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



" wrote:

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




Per Jessen

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

What is the value of "carrier_array_upper"?


skrev i en meddelelse
...
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





Bob Phillips

If then else, or select case is giving me a problem
 
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)



"Joel" wrote in message
...
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



" wrote:

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







All times are GMT +1. The time now is 06:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com