LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Posts: 2
Arrow Help with If statment to compare values

I need an If Then statement that will take entered value from A1:A10 and compares it through "low" and "high" range:
code low high
1 0 5
2 6 10
3 11 15
4 16 20
5 21 25
6 16 30
7 31 35
8 36 40
9 41 45
10 46 50
11 51 55
And then assigns correct code to cell B1:B10. For example if the entered value in cell A1 is 5, it will automatically enter code 1 to cell B1.
The If Then statement has to take value from A1:A2 and assign code to B1:B10.

I was thinking to do it this way:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If [A1] 0 And [A1] <= 5 Then
[B1] = 1
ElseIf [A1] <= 10 And [A1] = 6 Then
[B1] = 2
ElseIf [A1] <= 15 And [A1] = 11 Then
[B1] = 3
ElseIf [A1] <= 20 And [A1] = 16 Then
[B1] = 4
ElseIf [A1] <= 25 And [A1] = 21 Then
[B1] = 6
ElseIf [A1] <= 30 And [A1] = 26 Then
[B1] = 7
ElseIf [A1] <= 35 And [A1] = 31 Then
[B1] = 8
ElseIf [A1] <= 40 And [A1] = 36 Then
[B1] = 9
ElseIf [A1] <= 45 And [A1] = 41 Then
[B1] = 10
ElseIf [A1] <= 50 And [A1] = 46 Then
[B1] = 11
ElseIf Target <= 55 And [A1] = 51 Then
[B1] = 12
End If
End Sub

But this way I end up with a long code for each cell. Is there any other way?
Thank you for any help.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare 2 cells values with one IF statement jbsand1001 Excel Worksheet Functions 1 June 9th 05 06:15 PM
Excel Compare values in columns & display missing values in a new cpetta Excel Discussion (Misc queries) 1 April 2nd 05 05:51 AM
Formula to compare multiple rows values based on another column? Murph Excel Worksheet Functions 4 February 21st 05 02:44 AM
How do I write formula to compare two values and pull the resulta. Renee Excel Worksheet Functions 1 February 11th 05 01:31 AM
Is this simple I'm trying to compare values from 4 excel tables John Excel Worksheet Functions 1 December 2nd 04 04:00 PM


All times are GMT +1. The time now is 03:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"