looping through named ranges by naming convention- text versus integer problem

beckyinDC

Board Regular
Joined
Mar 24, 2011
Messages
56
I set up sets of 4 named ranges with "_1" through "_4" for several data items that pertain to quarterly processing.

for example:

CurrentMilestone_1, CurrentMilestone_2, etc
PassedAsOf_1, PassedAsOf_, etc

ok- so I need to color 4 cells with red, yellow or green based upon how many tests passed for that milestone...for troubleshooting, I am just using messageboxes as placeholders:

For i = 1 To 4
Select Case CStr(Application.Range("PassedQuarter_" & i).Text)
Case CStr(Application.Range("YellowThreshold_" & i).Text) To CStr(Application.Range("GreenThreshold_" & i).Text) - 1
MsgBox ("YELLOW! " & i)

Case Is >= CStr(Application.Range("GreenThreshold_" & i))
MsgBox ("GREEN! " & i)

Case Else
MsgBox ("RED! " & i)
End Select
Next


problem-

when the select/case statement evaluated a value of 3, it came up with GREEN when the greenthreshold was 21 and the yellowthreshold was 18- I think it is dealing with them as text instead of integers.

I tried to add cint and then switched to Cstr functions to make this work. Cstr is the right choice since cint returns type mismatch

Also tried "+0" to force the mnamed range values to be treated as numbers- result: type mismatch

Any help? thank you
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Why are you using CStr and .Text?

Are the values in the named ranges numbers?

Do you actually need any conversion functions?
Code:
For i = 1 To 4
        Select Case Range("PassedQuarter_" & i).Value
            Case Range("YellowThreshold_" & i).Value To Range("GreenThreshold_" & i).Value - 1
                MsgBox ("YELLOW! " & i)
            Case Is >= Range("GreenThreshold_" & i).Value
                MsgBox ("GREEN! " & i)
            Case Else
                MsgBox ("RED! " & i)
        End Select
    Next
 
Upvote 0
thank you- I was overthinking it and that did work!

I had had some trouble using .value for another issue I was working on and had changed over to referencing the text property when dealing with named ranges...for something it had worked better...but that was something else.

thanks again!
 
Upvote 0
Becky

I don't think using Text or Value would actually affect the use of a named range itself.

It might affect the use of the values in the named range though.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,733
Members
452,939
Latest member
WCrawford

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