ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checking to See if Range Values Add up to 100 (https://www.excelbanter.com/excel-programming/326135-checking-see-if-range-values-add-up-100-a.html)

Paige

Checking to See if Range Values Add up to 100
 
I have 2 cells (A1.A2) where numbers will be entered.
Once the user goes to cell A3, I need VBA code to check
to ensure that A1+A2 = 100, and if they do not, to show
an error message saying they do not (I know how to do the
messagebox, but when I go to Cell A3, nothing happens even tho A1+A2 does
not = 100). What I have so far is the following (which is in the specific
worksheet code window):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "A3" Then
If Range("A1").Value + Range("A2").Value <100 Then
MsgBox ("Error")
End If
End If
End Sub

I need code for this, not data validation or formuals. Thanks for any help
you can provide....pc


Ron de Bruin

Checking to See if Range Values Add up to 100
 
Use this Paige

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("A3"), Target) Is Nothing Then
If Range("A1").Value + Range("A2").Value < 100 Then
MsgBox "Error"
End If
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl



"Paige" wrote in message ...
I have 2 cells (A1.A2) where numbers will be entered.
Once the user goes to cell A3, I need VBA code to check
to ensure that A1+A2 = 100, and if they do not, to show
an error message saying they do not (I know how to do the
messagebox, but when I go to Cell A3, nothing happens even tho A1+A2 does
not = 100). What I have so far is the following (which is in the specific
worksheet code window):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "A3" Then
If Range("A1").Value + Range("A2").Value <100 Then
MsgBox ("Error")
End If
End If
End Sub

I need code for this, not data validation or formuals. Thanks for any help
you can provide....pc




Gary Brown[_5_]

Checking to See if Range Values Add up to 100
 
If Target.Address = "$A$3" Then

HTH,
Gary Brown



"Paige" wrote:

I have 2 cells (A1.A2) where numbers will be entered.
Once the user goes to cell A3, I need VBA code to check
to ensure that A1+A2 = 100, and if they do not, to show
an error message saying they do not (I know how to do the
messagebox, but when I go to Cell A3, nothing happens even tho A1+A2 does
not = 100). What I have so far is the following (which is in the specific
worksheet code window):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "A3" Then
If Range("A1").Value + Range("A2").Value <100 Then
MsgBox ("Error")
End If
End If
End Sub

I need code for this, not data validation or formuals. Thanks for any help
you can provide....pc


Mike Fogleman

Checking to See if Range Values Add up to 100
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("A3"), Target) Is Nothing Then
If Range("A1").Value + Range("A2").Value < 100 Then
MsgBox ("Error")
End If
End If
End Sub

Mike F
"Paige" wrote in message
...
I have 2 cells (A1.A2) where numbers will be entered.
Once the user goes to cell A3, I need VBA code to check
to ensure that A1+A2 = 100, and if they do not, to show
an error message saying they do not (I know how to do the
messagebox, but when I go to Cell A3, nothing happens even tho A1+A2 does
not = 100). What I have so far is the following (which is in the specific
worksheet code window):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "A3" Then
If Range("A1").Value + Range("A2").Value <100 Then
MsgBox ("Error")
End If
End If
End Sub

I need code for this, not data validation or formuals. Thanks for any
help
you can provide....pc




Paige

Checking to See if Range Values Add up to 100
 
Thanks guys - the revised code works perfectly!!!!

"Paige" wrote:

I have 2 cells (A1.A2) where numbers will be entered.
Once the user goes to cell A3, I need VBA code to check
to ensure that A1+A2 = 100, and if they do not, to show
an error message saying they do not (I know how to do the
messagebox, but when I go to Cell A3, nothing happens even tho A1+A2 does
not = 100). What I have so far is the following (which is in the specific
worksheet code window):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "A3" Then
If Range("A1").Value + Range("A2").Value <100 Then
MsgBox ("Error")
End If
End If
End Sub

I need code for this, not data validation or formuals. Thanks for any help
you can provide....pc



All times are GMT +1. The time now is 04:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com