Macro Help

banjoflanjo

New Member
Joined
Mar 20, 2008
Messages
44
Hello All,

I have 2 different macros, "macro1" & "macro2".

I also have a database of unique project numbers with a named range "list1".

Above the database I have an entry box named "findme".

What I need if possible is for the user to be able to enter a project number into the entry box, then for a macro to check the database, if the project is found in the list run "macro1", if not found in the list then run "macro2".

Can anyone help?

Thanks

Banjoflanjo
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try

Code:
Sub test()
If IsNumeric(Application.Match(Range("Findme"), Range("list1"), 0)) Then
    Call macro1
Else
    Call macro2
End If
End Sub
 
Upvote 0
Hi VoG,

Thanks for your reply,

This does not seem to work. All of the projects listed start with the letter "C" and is followed by a 7 digit number eg. C1234567

Does the "IsNumeric" bit affect this?

Banjoflanjo
 
Upvote 0
The IsNumeric is used to check whether a match was found. The code works for me with numeric and non-numeric data, including your example.

The code looks for an exact match. Check for leading or trailing spaces in the findme cell and in list1.
 
Upvote 0
Still doesnt work for some reason.

My database contains many columns and rows, does the code search all of the named range or just the first column like a vlookup?

Banjoflanjo
 
Upvote 0
Ah! Try

Code:
Sub test()
Dim Found As Range
Set Found = Range("list1").Find(what:=Range("findme").Value, lookat:=xlWhole)
If Not Found Is Nothing Then
    Call macro1
Else
    Call macro2
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,674
Messages
6,056,682
Members
444,882
Latest member
cboyce44

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