Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
checking two different cells Stefan - AW Excel Worksheet Functions 1 September 7th 09 05:28 PM
Checking cells contain a value ingalla Excel Programming 4 March 7th 07 02:53 PM
Checking range of cells for entry then checking for total Barb Reinhardt Excel Programming 1 October 13th 06 02:47 PM
Checking the Cells in Sheet1 with Cells in Sheet2 and replace Checking the cells in Sheet1 with Sheet2 Excel Worksheet Functions 1 August 19th 06 09:29 AM
copying cells by checking color of the cells JJJ010101 Excel Programming 1 January 24th 06 06:42 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"