ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Search that Exits Sub or Ends If (https://www.excelbanter.com/excel-programming/394315-if-search-exits-sub-ends-if.html)

Ryan Hess

If Search that Exits Sub or Ends If
 
Sheet1 D8 will be the value that I am searching for.

Sheet2 Column B is the location of all cell values that I want to search.

Trying to imbed this function in a macro to do the following.

(Granted I may have to use something other than just an If function but
that's why I'm posting) =)

If value in Sheet1 D8 = any of the cell values in Sheet2 Column B Then
MsgBox "Try again."
Exit Sub
Else
End If

I just can't seem to find the proper setup that I am looking for. Any help
would be greatly appreciated!

Thank you!

Jim Thomlinson

If Search that Exits Sub or Ends If
 
Here you go. Not too sure why you need the Exit Sub since you have the if
statement to control the flow of exectuins but to each his own...

If Application.WorksheetFunction.CountIf(Sheets("Shee t2").Columns("B"), _
Sheets("Sheet1").Range("D8").Value) = 1 Then
MsgBox "Try Again"
Else

End If

--
HTH...

Jim Thomlinson


"Ryan Hess" wrote:

Sheet1 D8 will be the value that I am searching for.

Sheet2 Column B is the location of all cell values that I want to search.

Trying to imbed this function in a macro to do the following.

(Granted I may have to use something other than just an If function but
that's why I'm posting) =)

If value in Sheet1 D8 = any of the cell values in Sheet2 Column B Then
MsgBox "Try again."
Exit Sub
Else
End If

I just can't seem to find the proper setup that I am looking for. Any help
would be greatly appreciated!

Thank you!



All times are GMT +1. The time now is 12:26 AM.

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