Is this number validation possible?
Hi Kenny
The code below is one way to do what you asked though it does contain
lots of loops so is not ideal though seems the most logical way to do
it in code to me at this moment. It will loop the used rows in column
1 and check the contents if it is 5 digits long it will begin to check
the numbers for 1 to 5 each time a number is found it will increament
a counter after checking all 5 digits i check the counter to see if it
is 5 which indicates that the numbers 1, 2, 3, 4, & 5 were found in
that cell.
Option Explicit
Dim lastRow As Integer
Dim cellLen As Integer
Dim iCell As Integer
Dim iNum As Integer
Dim iDigit As Integer
Dim nCounter As Integer
Private Sub CommandButton1_Click()
With ActiveSheet
lastRow = .UsedRange.Rows.Count
For iCell = 1 To lastRow
nCounter = 0
If Len(.Cells(iCell, 1).Value) = 5 Then
For iNum = 1 To 5
For iDigit = 1 To 5
If Mid(.Cells(iCell, 1).Value, iDigit, 1) = iNum Then
nCounter = nCounter + 1
Exit For
End If
Next iDigit
Next iNum
If nCounter = 5 Then
MsgBox "I fit the description"
End If
End If
Next
End With
End Sub
I hope this helps you out
Steve
|