![]() |
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 |
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 |
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 |
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 |
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