If (and( - with VBA

E

Eduardo

Hi and thank you in advance for your help
How do I write an statement that use if and with vba. here is what I need to
do,
I have information saved in one sheet "Projects" with 4 columns, Client,
Project name, Project # and Business. then I have and userform to to apply
expenses against each project so I need to compare the information enter in
each textbox with the columns in the data base if one of them doesn't match a
message will show up and will not allow the user to continue until is fixed.
an example will be
Client= A
Project name = A1
Project # = 1
Business = APP
so in order to apply anything to project # 1 all the others fields entered
have to match A, A1 & APP
I am thinking in something like,
if(and(textbox1=A:A, textbox2=B:B, textbox3=C:C, textbox4=D:D) then
Else
msgbox = " Information doesn't belong to project #"
 
B

Bob Phillips

RowNum = 0
On Error Resum Next
RowNum =
Application.Match(1,(Textbox1.Text=A1:A100)*(Textbox2.Text=B1:B100)*(Textbox3.Text=C1:C100)*(Textbox4.Text=D1:D100),0)
On Error Goto 0
If RowNum = 0 Then

MsgBox " Information doesn't belong to project #"
Else

...
End If

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
E

Eduardo

Hi Bob,
Thank you so much that was exactly what I was looking for, just one more
question when the error message shows up I press enter and all the
information is deleted is any way that at least the project # stays so the
user goes and change whatever was wrong in the other fields. Thank you
 
E

Eduardo

Hi Bob, I checked when the information doesn't match but if the information
match it gives me the error message as well, thank you for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top