Using If Statement in VBA

snownut2

New Member
Joined
Sep 22, 2011
Messages
18
I am very new to VBA and have the following problem;

I have a worksheet with 10 columns and 90 rows, I would like to sum 2 cells in the same row then compare the result to a 3rd cell in the same row, If the sum of the 2 cells is greater then the 3rd cell I would like to display a Message box.

We can call cells 1 & 2 column b and f and cell 3 column d

The other If statement shown is for another function not completed yet, so it needs to stay.

I have already started the framework in the VBA editor see below.


Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
Range("H1").Value = Date
Application.EnableEvents = True

If Target.Column > 5 And Target.Column < 7 Then
MsgBox "enter text here"

Else

If Target.Column > 7 And Target.Column < 9 Then
MsgBox "enter text here"

Exit Sub

End If

End If


End Sub


Thanks,
Bruce
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You could do this by using Excel's Data Validation feature.
  • Select columns B, D , and F (Ctrl+click on each column)
  • Select from the menu Data\Data Validation
    • On the Settings tab:
      • Allow: Custom
      • Formula: =B1+F1< D1
    • On the Error Alert tab
      • Select the type of message box you want and enter the message.
    • OK

Note: For Data Validation if the formula is True, then no message box. That's why the less than operator < is used.
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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