Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default If no FIND value is found, then a Msgbox to say so and exit sub

Hello Excel users and experts,

Win XP, Excel 2002

A number is scanned into cell A1 and the below code is called through a
change event macro. It finds that value in range aList and a date stamp is
entered 2 columns to the right of the find value. This works fine.

However, if there is NOT a value found in aList, then for some reason the
date stamp is entered in first row of aList, 2 columns over. What would be
the code to prompt a message box "Not Valid No." when there is no find? I
can't figure out how to "catch" the fact that a number was not found.

Sub BookReturnDate()

Dim aList As Range
Dim Bcode As Variant
Bcode = Range("A1").Value
If Bcode = "" Then Exit Sub

Set aList = Range("G2:G2505")
On Error Resume Next

aList.Select
Selection.Find(What:=Bcode).Activate
ActiveCell.Offset(0, 2).Value = Now

'If no find then msgbox "Goof Up"

End Sub

Thanks for your help,
Regards,
Howard


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default If no FIND value is found, then a Msgbox to say so and exit sub

The alterations are untested.

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------
Sub BookReturnDate()

Dim aList As Range
Dim rngFind as Range
Dim Bcode As Variant

Bcode = Range("A1").Value
If Bcode = "" Then Exit Sub

Set aList = Range("G2:G2505")
On Error Resume Next

Set rngFind = aList.Find(What:=Bcode)
If not rngFind is Nothing Then
rngFind.Offset(0, 2).Value = Now
Else
msgbox "Goof Up"
End If

End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default If no FIND value is found, then a Msgbox to say so and exit sub

Hi Paul,

Thanks a ton for the code advice. Pretty smooth. I did have to change it a
bit so the "Found" cell would be selected and brought into view. This is to
allow a visual verification that the date stamp is in the correct place.
(End users wishes) The Goof Up message box is the watchdog of that but...

Again, thanks a ton Paul, and Chip.
Regards,
Howard

wrote in message
...
The alterations are untested.

HTH
Paul
--------------------------------------------------------------------------

------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------

------------------------------------
Sub BookReturnDate()

Dim aList As Range
Dim rngFind as Range
Dim Bcode As Variant

Bcode = Range("A1").Value
If Bcode = "" Then Exit Sub

Set aList = Range("G2:G2505")
On Error Resume Next

Set rngFind = aList.Find(What:=Bcode)
If not rngFind is Nothing Then
rngFind.Offset(0, 2).Value = Now
Else
msgbox "Goof Up"
End If

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
colum is not found thats missing a column B how to find it meena Excel Worksheet Functions 1 July 17th 09 10:36 AM
FIND function does not return ZERO when text is not found DOUG01A Excel Worksheet Functions 5 August 5th 08 05:56 PM
How to find a row since I found a value in a column? see example [email protected] Excel Worksheet Functions 1 April 25th 06 05:45 PM
Find text in another workbook and paste if found match - VBA Pasmatos Excel Discussion (Misc queries) 1 November 10th 05 01:00 PM
Copy Rows found using Find All feature Scott H Excel Discussion (Misc queries) 3 May 2nd 05 06:04 PM


All times are GMT +1. The time now is 08:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"