V
Vika
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.
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.