Find value in cell, if not there then do something

AJTatsuo

New Member
Joined
Jun 4, 2020
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
  2. MacOS
  3. Mobile
Hi.

I’ve got a piece of code that hunts for a name based on a name in one data set and will transpose the information related to that name to a collection database.

This is fed by a weekly report; the feed is manually ran by an admin.

Staffing frequently changes so I am trying to identify when the name doesn’t exist in my central database and prompt VBA to create a template for the new person before adding the data.

I have accomplished the majority of this but the issue I’m coming up against is; when an error throws because nothing is found I need to capture this and do one thing in response or if the error isn’t thrown move on.

Complication is I am in a called subroutine from a subroutine in the middle of a loop.

I can’t find a way to convert the error to a true or false.

The GoTo is clunky, only let’s you skip a portion of the code rather than if this else type response; plus every forum I have read warns me off the GoTo spaghetti nonsense.

Have I hit an impossible wall with this.

I am currently using:

Range(“A:AG”).Find(What:=EMDName).Address.Select

to hunt; the variable “EMDName”has been declared and populated before this sub starts.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi & welcome to MrExcel.
How about
VBA Code:
Dim Fnd As Range
Set Fnd = Range("A:AG").Find(EMDName)
If Not Fnd Is Nothing Then
   MsgBox "Not found"
   Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,179
Members
448,871
Latest member
hengshankouniuniu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top