Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA logic test in Excel

Status
Not open for further replies.

Daya100

Programmer
Jan 11, 2002
21
US
I'm really an access programmer and can't figure out how do do anything in excel. Basically, I want some code that says if A1 + B1 <> C1 then... - I know how to put in the message box.

Also, how do I require a field? SO they can't save or move to another sheet if the cell is empty.

I appreciate any help - I am very frustrated.
 
Here is the answer to the first part of your
question...

If (Range(&quot;Sheet1!A1&quot;).Value + Range(&quot;Sheet1!B1&quot;).Value) _
<> Range(&quot;Sheet1!C1&quot;).Value Then
MsgBox &quot;Whatever&quot;
End If

- vbMax
 
Hi,
Well here is a way...
Code:
'I like to use Cells(RowNbr, ColNbr)
'   rather than the &quot;A1&quot; format--
'much easier to manipulate...

'load data into variables
    For iCol = 1 To 3
        Select Case iCol
            Case 1
                ValA = Cells(1, iCol).Value    'row 1, col A
            Case 2
                ValB = Cells(1, iCol).Value    'row 1, col B
            Case 3
                ValC = Cells(1, iCol).Value    'row 1, col C
        End Select
    Next
   
    If ValA + ValB <> ValC Then
        'your action
    End If
As for chaecking values, you can do a routine tied to the Worksheet_Deactivate Event. However, since Save is a canned toolbar routine, you will have to create your own toolbar that will perform the data validation routine before saving.

Hope this helps. :) Skip,
metzgsk@voughtaircraft.com
 
Hey Skip and Max,

Thanks for the replies - very helpful. I have another question though, Skip. How do I add in there that if ValA or ValB are null then I don't want the message box to run. I tried adding if not IsNull ValA and ValA+ValB.....
Thanks again!!!
Amy
 
Try using
Code:
If IsEmpty(ValA + ValB) Then ...
Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top