Hello ladies and gentlemen. I have a rather frustrating issue that dates a few months back, so I hope to solve it today.
The following code tests a value in Column A. If the value is between 1-5 or equal to 11, column B will return the string A. It works.
Sub Numbers()
Dim LastRow As Long, r As Long
Dim strL As String
LastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 5 Step -1
If (Cells(r, "A").Value > 0 And Cells(r, "A").Value <= 5) Then
strL = "A"
ElseIf Cells(r, "A").Value = 11 Then
strL = "A"
End If
Cells(r, "B") = strL
Next r
Application.ScreenUpdating = True
End Sub
And I believe the equivalent (replacing If with Select Case) goes:
Sub Numbers()
Dim LastRow As Long, r As Long
Dim strL As String
LastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 5 Step -1
Select Case Cells(r, "A").Value
Case Cells(r, "A").Value > 0 And Cells(r, "A").Value <= 5
strL = "A"
Case Cells(r, "A").Value = 11
strL = "A"
End Select
Cells(r, "B") = strL
Next r
Application.ScreenUpdating = True
End Sub
However, if I run the second code with matching values in Column A (11, 1, 3, etc), nothing happens. Well, maybe something happens, but the values in Column B remain blank.
Could anybody tell me why?
Bookmarks