Hi again
Here's a more complete setup. Test1 calls a different macro (1, 2 or 3) depending on the
content category. Test2 calls the same code for all three "if not 4". So place your code
into the proper Macro1 (and/or 2 or 3). Note that the one-cell range is passed to them, so
use R and not ActiveCell or Selection there. I've also removed your "select", so the user
is not bothered with his cursor being moved. Put it back if you disagree.
Sub test1()
Dim R As Range
For Each R In Range("H2:J250")
If Not IsEmpty(R) Then
Select Case ValCategory(R)
Case 1
Call Macro1(R)
Case 2
Call Macro2(R)
Case 3
Call Macro3(R)
Case Else
End Select
End If
Next
End Sub
Sub test2()
Dim R As Range
For Each R In Range("H2:J250")
If Not IsEmpty(R) Then
Select Case ValCategory(R)
Case 1 To 3
Call Macro1(R)
Case Else
End Select
End If
Next
End Sub
Sub Macro1(R As Range)
MsgBox R.Address & Chr(10) & R.Value, , "Macro1"
End Sub
Sub Macro2(R As Range)
MsgBox R.Address & Chr(10) & R.Value, , "Macro2"
End Sub
Sub Macro3(R As Range)
MsgBox R.Address & Chr(10) & R.Value, , "Macro3"
End Sub
Function ValCategory(R As Range) As Byte
'1 = capital letter
'2 = number 1 to 99
'3 = 1 + 2
'4 = something else
Select Case Len(CStr(R.Value))
Case 1
Select Case Asc(R.Value)
Case 48 To 57
ValCategory = 2
Case 64 To 90
ValCategory = 1
Case Else
ValCategory = 4
End Select
Case 2
If IsNumeric(R.Value) Then
Select Case R.Value
Case 1 To 99
ValCategory = 2
Case Else
ValCategory = 4
End Select
Else
ValCategory = 4
End If
Case 3
Select Case Asc(R.Value)
Case 64 To 90
If IsNumeric(Mid(R.Value, 2)) Then
Select Case Val((Mid(R.Value, 2)))
Case 1 To 99
ValCategory = 3
Case Else
ValCategory = 4
End Select
Else
ValCategory = 4
End If
Case Else
ValCategory = 4
End Select
Case Else
ValCategory = 4
End Select
End Function