ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checking two cells (https://www.excelbanter.com/excel-programming/392631-checking-two-cells.html)

Tanya

Checking two cells
 
Hi,

I have the following in a spreadsheet:
I J
1 1.0 1.0
2 2.0 0.3
3 1.0
4 1.2
5 2.3 2.3

I would like to be able to put some code behind that loops through the above
range checks to see if for example the sum of I1:J1 is equal or greater than
2 and then throw up a msgbox otherwise do nothing.
Is this possible?
normally i would keep working at it but the project i am on is due by end of
today so thankyou all in advance for any help you can provide. 8-)

Tanya

JLatham

Checking two cells
 
Tanya, the first Sub below will do as you have requested, although you may
not want to have to respond to all the messages, but ....
The second routine will not nag you with messages, but will color the cell
pair involved red to point them out instead.

Sub LotsOfMessages()
Dim lastRow As Long
Dim lCounter As Long
Dim baseCell As Range

Set baseCell = Range("A1")
lastRow = baseCell.End(xlDown).Row - 1
For lCounter = 0 To lastRow
If baseCell.Offset(lCounter, 0) + _
baseCell.Offset(lCounter, 1) 2 Then
MsgBox "Row " & lCounter + 1 & " is 2"
End If
Next
End Sub
Sub ColorMarkThem()
Dim lastRow As Long
Dim lCounter As Long
Dim baseCell As Range

Set baseCell = Range("A1")
lastRow = baseCell.End(xlDown).Row - 1
For lCounter = 0 To lastRow
baseCell.Offset(lCounter, 0).Interior.ColorIndex = _
xlNone ' clear any prior coloring
baseCell.Offset(lCounter, 1).Interior.ColorIndex = _
xlNone ' clear any prior coloring
If baseCell.Offset(lCounter, 0) + _
baseCell.Offset(lCounter, 1) 2 Then
baseCell.Offset(lCounter, 0).Interior.ColorIndex = 3
baseCell.Offset(lCounter, 1).Interior.ColorIndex = 3
End If
Next
End Sub


"Tanya" wrote:

Hi,

I have the following in a spreadsheet:
I J
1 1.0 1.0
2 2.0 0.3
3 1.0
4 1.2
5 2.3 2.3

I would like to be able to put some code behind that loops through the above
range checks to see if for example the sum of I1:J1 is equal or greater than
2 and then throw up a msgbox otherwise do nothing.
Is this possible?
normally i would keep working at it but the project i am on is due by end of
today so thankyou all in advance for any help you can provide. 8-)

Tanya



All times are GMT +1. The time now is 10:03 PM.

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