PC Review


Reply
Thread Tools Rate Thread

Checking two cells

 
 
=?Utf-8?B?VGFueWE=?=
Guest
Posts: n/a
 
      4th Jul 2007
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 With Quote
 
 
 
 
=?Utf-8?B?SkxhdGhhbQ==?=
Guest
Posts: n/a
 
      4th Jul 2007
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking cells contain a value =?Utf-8?B?aW5nYWxsYQ==?= Microsoft Excel Programming 4 7th Mar 2007 02:53 PM
Checking range of cells for entry then checking for total =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 1 13th Oct 2006 02:47 PM
Checking the Cells in Sheet1 with Cells in Sheet2 and replace =?Utf-8?B?Q2hlY2tpbmcgdGhlIGNlbGxzIGluIFNoZWV0MSB3 Microsoft Excel Worksheet Functions 2 19th Aug 2006 09:29 AM
Checking the Cells in Sheet1 with Cells in Sheet2 and replace =?Utf-8?B?Q2hlY2tpbmcgdGhlIGNlbGxzIGluIFNoZWV0MSB3 Microsoft Excel Worksheet Functions 0 19th Aug 2006 07:33 AM
copying cells by checking color of the cells JJJ010101 Microsoft Excel Programming 1 24th Jan 2006 06:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:55 AM.