Tim Hanson
Member
I am trying to get a hand on using array's and not quite getting it here.
I think my problem is here: HasNumber(dat(i, 1).Text), in that "dat(i, 1)" is a Varient so that "dat(i, 1).Text" does not make sense, but I am not sure how to handle the mismatch
Thanks
I think my problem is here: HasNumber(dat(i, 1).Text), in that "dat(i, 1)" is a Varient so that "dat(i, 1).Text" does not make sense, but I am not sure how to handle the mismatch
Thanks
Code:
Sub DoesCellHaveNumer()
Dim dat As Variant
Dim ws As Worksheet
Dim rng As Range
Dim LR As Long
Dim i As Long
Set ws = ThisWorkbook.Sheets("UnPivot")
LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
Set rng = ws.Range("D2:D" & LR)
dat = rng.Value
For i = LBound(dat, 1) To UBound(dat, 1)
If HasNumber(dat(i, 1).Text) Then
MsgBox "Yes has number"
Else
MsgBox "No does not"
End If
Next i
End Sub
Code:
Function HasNumber(strData As String) As Boolean
Dim iCnt As Integer
For iCnt = 1 To Len(strData)
If IsNumeric(Mid(strData, iCnt, 1)) Then
HasNumber = True
Exit Function
End If
Next iCnt
End Function