Checking two cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top