Hi,
I'm guessing the # wildcard won't work in the Excel find method? It won't for me anyway...
I need to be able to look for a uk postcode format, which could be any of the following:
??# #??
?# #??
??## #??
?## #??
??#? #??
I'd like to do it this way:
The purpose is that I have a large number of Excel workbooks to investigate, to see if they hold address data. I plan to loop through the books, run the above, feeding the function one of the above formats in sequence. If I find more than three instances in total of any format set a flag to true:
It won't work though :-(
Any advice would be appreciated.
Thanks, Iain
I'm guessing the # wildcard won't work in the Excel find method? It won't for me anyway...
I need to be able to look for a uk postcode format, which could be any of the following:
??# #??
?# #??
??## #??
?## #??
??#? #??
I'd like to do it this way:
Code:
Public Function test_find(strWhat As String) As Boolean
Dim c
Dim strFirstAddress As String
Dim i As Integer
i = 0
Set c = Cells.Find(what:=strWhat, _
LookIn:=xlValues)
If Not c Is Nothing Then
i = i + 1
strFirstAddress = c.Address
Do While Not ((c Is Nothing And c.Address <> strFirstAddress) Or i > 2)
Set c = Cells.FindNext(c)
i = i + 1
Loop
End If
If i >= 2 Then
test_find = True
Exit Function
Else
test_find = False
Exit Function
End If
End Function
The purpose is that I have a large number of Excel workbooks to investigate, to see if they hold address data. I plan to loop through the books, run the above, feeding the function one of the above formats in sequence. If I find more than three instances in total of any format set a flag to true:
Code:
Function Got_Postcodes() As Boolean
Dim a as integer
a = 0
a = test_find(??# #??)
if a < 3 Then
a = a + test_find("?# #??")
end if
if a < 3 Then
a = a + test_find("??## #??")
end if
etc...
If a > 2 Then
Got_Postcodes = True
Else
Got_Postcodes = False
End If
End Function
It won't work though :-(
Any advice would be appreciated.
Thanks, Iain