+ Reply to Thread
Results 1 to 5 of 5

Looping using Select Case Statement

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    los angeles, USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Looping using Select Case Statement

    I have a range of scores say in Column A and they relate to one of the corresponding codes in the REFERENCE TABLE.
    So a score of 621 would be between 620 & 639 I need to fill a column with the corresponding code# based on the table below.
    My code will fill the desired column but it doesn't loop through. It fills the column with the first select CASE statement so the whole column fills in with "FICO1"
    Desired Result should look like this
    Column A Column B
    621 FICO7
    700 FICO3
    681 FICO4


    REFERENCE TABLE
    Low High Code#
    740 900 FICO1
    720 739 FICO2
    700 719 FICO3
    680 699 FICO4
    660 679 FICO5
    640 659 FICO6
    620 639 FICO7



    Sub CategoryChanger()

    Dim rng As Range
    Dim r As Range
    Dim result As String

    Sheet1.Activate
    '## Defines a range to represent the cells over which you would like to iterate:


    Set rng = Range("Loan_Credit_Score__FICO")
    '## Iterate each cell in the Range defined "rng"
    For Each r In rng.Cells
    Select Case r.Value

    Case (Value >= 740 And Value <= 900)
    result = "FICO1"
    Case (Value >= 720 And Value <= 739)
    result = "FICO2"
    Case (Value >= 700 And Value <= 719)
    result = "FICO3"
    Case (Value >= 680 And Value <= 699)
    result = "FICO4"
    Case (Value >= 660 And Value <= 679)
    result = "FICO5"
    Case (Value >= 640 And Value <= 659)
    result = "FICO6"
    End Select

    '## Put result in the cell 25 columns to right
    r.Offset(0, 25).Value = result
    Next
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Looping using Select Case Statement

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Looping using Select Case Statement

    You could do this with VLOOKUP as well, have you considered that instead?

    Using a reference table that and the approximate match argument would allow you to pull the FICO# you want. Ill edit to add an example shortly.

    Ref table:
    0 | FICO8
    620 | FICO7
    640 | FICO6
    660 | FICO5
    680 | FICO4
    700 | FICO3
    720 | FICO2
    740 | FICO1

    then as a formula for your codes column (B):

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Basically TRUE allows it to find the closest value not over the lookup value and use that line to return from. IE: 619 = 0 = FICO8, 620 = 620 = FICO7, 621 = 620 = FICO7, etc.

    Not sure if you have a macro doing much more and this is just part of it, but VLOOKUp would be a much simpler way to do only this.
    Last edited by Zer0Cool; 12-07-2017 at 03:29 PM.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Looping using Select Case Statement

    If using Select Case. I'd do it like below.

    Since Select Case will exit at first match... going from <620 ... <=900 will work as well with out limiting to whole numbers.


    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  5. #5
    Registered User
    Join Date
    08-21-2013
    Location
    los angeles, USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Looping using Select Case Statement

    Norie - that worked like a charm.
    Awesome .. this was really bugging me for two days. You are the man!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Select Case with multiple lines in a case statement?
    By jGKpZ8a33sPrnqX8fam7 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-02-2017, 10:25 AM
  2. Go to Next case in a Select Statement?
    By Speshul in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2014, 12:19 PM
  3. SQL select where case statement!
    By Jollyfrog in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-25-2010, 12:43 PM
  4. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08:55 PM
  5. looping select case statement
    By pik in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-08-2008, 08:11 PM
  6. Select Case Statement Help
    By Jeugo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2006, 03:45 PM
  7. select case statement
    By jrd269 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-03-2005, 12:05 PM

Tags for this Thread

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