Check 3 cells for specific content

T

Terri

Hello,
Is it possible to use code to check the value of 3
different cells at the same time for specific content?
Example:
A1 should = Part Number
B1 should = Order Quantity
C1 should = Order Date

If the spreadsheet doesn't have this cell content in thid
location,
Then MsgBox '"Wrong File"

Your help is appreciated so much!
 
F

Frank Kabel

Hi
in VBA try
sub foo()
dim str
with activesheet
str=.range("A1").value & .range("B1").value & .range("C1").value
end with
if lcase(str)<>"part numberorder quantityorder date" then
msgbox "wrong content
end if
end sub
 
P

Pierre

This few lines should help you :


if range("A1")<> range("Part Number") and _
range("B1")<> range("Order Quantity") and _
range("C1")<> range("Order Date") then

MgBox '"Wrong File"

Endi
 
D

Dave Peterson

I would have guessed that the OP was checking a header row for real constants:

Option Explicit
Sub testme()
With Worksheets("sheet1")
If LCase(.Range("A1").Value) = "part number" _
And LCase(.Range("B1").Value) = "order quantity" _
And LCase(.Range("C1").Value) = "order date" Then
'it's ok!
Else
MsgBox "Wrong File"
Exit Sub '???
End If
End With
End Sub

In either case, I think you wanted to use OR's instead of AND's. Or use AND's
and change <> to = and put the msgbox in the "else" portion of your statement.
 
Top