View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default finding only numeric values in a worksheet using vb.net?

I don't think you can use Find to find the cells and Find doesn't support
Regular Expressions. Try code like

Function GetValues(InRange As Range, Length As Long) As Range
Dim Res As Range
Dim R As Range

For Each R In InRange.Cells
If IsNumeric(R.Text) = True Then
If Len(R.Text) = Length Then
If Res Is Nothing Then
Set Res = R
Else
Set Res = Application.Union(Res, R)
End If
End If
End If
Next R

Set GetValues = Res
End Function

You can then call this function with code like:

Sub AAA()
Dim R As Range
Dim RR As Range
Set RR = GetValues(InRange:=Range("A1:A10"), Length:=11)
If RR Is Nothing Then
Debug.Print "NOT FOUND"
Else
For Each R In RR
Debug.Print R.Address, R.Text
Next R
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)



"Andrius B." wrote in message
...
Hi all.
Maybe smb could make an advice how to do this:

I have to find all the rows in a Excel worksheet, which contain cell with
a 11 digit numeric value.

E.g. two rows each with 3 cells with values:
------------------------------------
Will | Smith | 4524574561

Gerry | Smith | LowStreet 20
------------------------------------


So, the first row should be accepted, and the second - ignored.

I tried different examples using oSheet.Cells.Find(What:=...
but unsuccesfully.

Is there a way to use regular expressions

Thanks in advance.