#1   Report Post  
Mark1
 
Posts: n/a
Default Simple VBA question

Can anybody tell me why this isn't working? I have a list of Last names in
A2:A6 and a list of first names in B2:B6. It works if I put a match in cells
G6 and H6, but gives me an error if there is no match. Thanks for the help.

Sub Macro1()
Dim a As String
Dim b As String
Dim c As Boolean
Dim d As Boolean

a = Range("G6").Value
b = Range("H6").Value
c = WorksheetFunction.IsError(WorksheetFunction.Match( a, Range("A2:A6"),
0))
d = WorksheetFunction.IsError(WorksheetFunction.Match( b, Range("B2:B6"),
0))

If c = False And d = False Then
MsgBox ("This name has already been entered" & Chr(13) _
& "please enter another name.")
End If
End Sub

  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Mark,

Try this

Dim a As String
Dim b As String
Dim c
Dim d

a = Range("G6").Value
b = Range("H6").Value
c = Application.Match(a, Range("A2:A6"), 0)
d = Application.Match(b, Range("B2:B6"), 0)
If Not IsError(c) And Not IsError(d) Then
MsgBox ("This name has already been entered" & Chr(13) _
& "please enter another name.")
End If


What if the names are found in different rows?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mark1" wrote in message
...
Can anybody tell me why this isn't working? I have a list of Last names

in
A2:A6 and a list of first names in B2:B6. It works if I put a match in

cells
G6 and H6, but gives me an error if there is no match. Thanks for the

help.

Sub Macro1()
Dim a As String
Dim b As String
Dim c As Boolean
Dim d As Boolean

a = Range("G6").Value
b = Range("H6").Value
c = WorksheetFunction.IsError(WorksheetFunction.Match( a,

Range("A2:A6"),
0))
d = WorksheetFunction.IsError(WorksheetFunction.Match( b,

Range("B2:B6"),
0))

If c = False And d = False Then
MsgBox ("This name has already been entered" & Chr(13) _
& "please enter another name.")
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
basic pie chart question KayR Charts and Charting in Excel 4 January 23rd 05 08:16 PM
Ploting dates against a calendar and not as a simple events Barb Reinhardt Charts and Charting in Excel 2 January 22nd 05 02:41 AM
Well that's strange... TAB question CrankyLemming Excel Discussion (Misc queries) 3 December 1st 04 07:52 AM
rota question - very tricky... Michelle Tucker Excel Discussion (Misc queries) 0 November 27th 04 11:55 AM
Importing Question! Otto Moehrbach Excel Discussion (Misc queries) 0 November 26th 04 07:04 PM


All times are GMT +1. The time now is 02:22 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"