ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   checking in vba if item is found within a range (https://www.excelbanter.com/excel-programming/369195-checking-vba-if-item-found-within-range.html)

DJB

checking in vba if item is found within a range
 
I have used the following code in the past but it no longer works in the
newer versions of Excel. Is there another way to check if an item is found or
not within a range.

Evern though it shows c equal to Nothing in watch mode, the code used below
gives an error.

Sub testFindDate()
With Range("K4:K45")
Set c = .Find("7/1/2006")
End With
If c.Value = "Nothing" Then
MsgBox "not found"
Else
MsgBox c.Address
End If
--
djb

Jim Cone

checking in vba if item is found within a range
 
Sub testFindDate()
Dim c As Excel.Range
Set c = Range("K4:K45").Find("7/1/2006")
If c Is Nothing Then
MsgBox "not found"
Else
MsgBox c.Address
End If
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"djb"

wrote in message
I have used the following code in the past but it no longer works in the
newer versions of Excel. Is there another way to check if an item is found or
not within a range.
Evern though it shows c equal to Nothing in watch mode, the code used below
gives an error.

Sub testFindDate()
With Range("K4:K45")
Set c = .Find("7/1/2006")
End With
If c.Value = "Nothing" Then
MsgBox "not found"
Else
MsgBox c.Address
End If
--
djb


All times are GMT +1. The time now is 10:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com