Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 14
Default COMPARING TWO COLUMNS AND DISPLAYING MSGBOX

Hello everyone,

Am having two values in A1 and B1.
The cell C1 has one value.
I need a msgbox to pop up if either A1 or B1 greater than C1.
Please help.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 168
Default COMPARING TWO COLUMNS AND DISPLAYING MSGBOX

On Saturday, December 15, 2012 12:28:56 AM UTC-8, naga rajan wrote:
Hello everyone,



Am having two values in A1 and B1.

The cell C1 has one value.

I need a msgbox to pop up if either A1 or B1 greater than C1.

Please help.


Hi naga rajan,

Try this in the worksheet code module.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1").Value Or Range("B1").Value Range("C1") Then
MsgBox "A1 or B1 is greater than C1", vbOKOnly, "High Hopes"
End If
End Sub

HTH
Regards,
Howard
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 829
Default COMPARING TWO COLUMNS AND DISPLAYING MSGBOX

wrote:
naga rajan wrote:
I need a msgbox to pop up if either A1 or B1 greater than C1.

[....]
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1").Value Or Range("B1").Value Range("C1") Then
MsgBox "A1 or B1 is greater than C1", vbOKOnly, "High Hopes"
End If
End Sub


Correction:

If Range("A1") Range("C1") Or Range("B1") Range("C1") Then

Also note that the Worksheet_Change event macro goes into a worksheet
module, not a normal module. Right-click on the worksheet tab to open the
worksheet module in the VBA window.

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 168
Default COMPARING TWO COLUMNS AND DISPLAYING MSGBOX

On Saturday, December 15, 2012 8:15:50 AM UTC-8, joeu2004 wrote:
wrote:

naga rajan wrote:


I need a msgbox to pop up if either A1 or B1 greater than C1.


[....]

Private Sub Worksheet_Change(ByVal Target As Range)


If Range("A1").Value Or Range("B1").Value Range("C1") Then


MsgBox "A1 or B1 is greater than C1", vbOKOnly, "High Hopes"


End If


End Sub




Correction:



If Range("A1") Range("C1") Or Range("B1") Range("C1") Then



Also note that the Worksheet_Change event macro goes into a worksheet

module, not a normal module. Right-click on the worksheet tab to open the

worksheet module in the VBA window.


Whoa, good catch Joeu2004! It's not clear to me why my line produces the msgbox when both A1 & B1 are LESS than C1. And I tested my code, but missed that somehow...???

Howard
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 829
Default COMPARING TWO COLUMNS AND DISPLAYING MSGBOX

wrote:
If Range("A1").Value Or Range("B1").Value Range("C1") Then

[....]
It's not clear to me why my line produces the msgbox when
both A1 & B1 are LESS than C1.


Because A1 < 0 (presumably).

Your if-statement reads: "if A1 is true or if B1 C1, then ....".

Any non-zero value is considered "true". So "if A1 is true" is false only
when A1 = 0.

Since "A1 is true" is (almost) always true, the true/false value of the 2nd
part (B1 C1) does not matter. "TRUE OR anything" is true.




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 168
Default COMPARING TWO COLUMNS AND DISPLAYING MSGBOX

On Saturday, December 15, 2012 11:18:36 AM UTC-8, joeu2004 wrote:
wrote:

If Range("A1").Value Or Range("B1").Value Range("C1") Then


[....]

It's not clear to me why my line produces the msgbox when


both A1 & B1 are LESS than C1.




Because A1 < 0 (presumably).



Your if-statement reads: "if A1 is true or if B1 C1, then ....".



Any non-zero value is considered "true". So "if A1 is true" is false only

when A1 = 0.



Since "A1 is true" is (almost) always true, the true/false value of the 2nd

part (B1 C1) does not matter. "TRUE OR anything" is true.


Thanks, good stuff to digest for lurkers like me.

Howard
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 14
Default COMPARING TWO COLUMNS AND DISPLAYING MSGBOX

Hello,

Thanks for the help.
When I define the range to A1:A100 C1 its giving mismatch error.
I want to display a msgbox when the value of A1:A100 or B1:B100 C1.
Please help.
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
Msgbox not displaying davethewelder Excel Programming 6 April 10th 08 04:04 PM
Displaying A MsgBox for X Seconds Mark Excel Programming 1 July 15th 05 02:41 PM
MsgBox not displaying right away Ray Kanner[_2_] Excel Programming 1 April 7th 05 02:30 AM
Comparing values in two columns and displaying missing values in n cpetta Excel Programming 1 April 2nd 05 06:18 AM
Comparing Cells and Displaying Data Keith Brown Excel Worksheet Functions 1 February 9th 05 06:42 PM


All times are GMT +1. The time now is 06:18 AM.

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

About Us

"It's about Microsoft Excel"