Excel place a vaue in a cell if a number is in a certain range

Closed
rangebob Posts 1 Registration date Wednesday September 17, 2014 Status Member Last seen September 17, 2014 - Sep 17, 2014 at 12:17 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Sep 23, 2014 at 11:18 AM
I need to setup ranges and place a number associated with-in that range.

150
300
450
600
750
900

This data is from column M. I need to be able to look at this number and then a range setup

1-510 1
511-1020 2
1021-1530 3
1531-2040 4
2041-2550 5

So the results that I'm looking for. If the 4th number (600), it is in range 511-1020, I need 2 returned as the answer. If the number is 1599 I need a 4 returned.

Thanks for any and all help.
Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Sep 23, 2014 at 11:18 AM
Hi Rangebob,

Try the following code:
Sub RunMe()
For Each cell In Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    If cell >= 1 And cell <= 510 Then
        cell.Offset(0, 1) = 1
    ElseIf cell >= 511 And cell <= 1020 Then
        cell.Offset(0, 1) = 2
    ElseIf cell >= 1021 And cell <= 1530 Then
        cell.Offset(0, 1) = 3
    ElseIf cell >= 1531 And cell <= 2040 Then
        cell.Offset(0, 1) = 4
    ElseIf cell >= 2041 And cell <= 2550 Then
        cell.Offset(0, 1) = 5
    End If
Next cell
End Sub 


To use code:
From Excel hit Alt + F11 > top menu Insert > select Module > Paste code in big white field > close window > back at Excel hit Alt + F8 > double click RunMe.

Best regards,
Trowa
0