Need help with Msgbox Code

jwilso81

New Member
Joined
Apr 5, 2013
Messages
3
I am trying to write a code to display a msgbox when the value of one cell is greater than they value of another. For example, if (O4) is greater than (P4) or (L4) then the msgbox will appear. If either (P4) or (L4) are greater or equal to (O4) then NO msgbox will appear. Also, I need this code to apply to each row separately, however, I need a code for about 30 rows. In other words it would look something like:
if (O4) is greater than (P4) or (L4) then the msgbox will appear
if (O6) is greater than (P6) or (L6) then the msgbox will appear
if (O8) is greater than (P8) or (L8) then the msgbox will appear
if (O10) is greater than (P10) or (L10) then the msgbox will appear...ect.

Any help would be greatly appreciated.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi,

Try this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    For row_no = 1 To 30
        If Cells(row_no, "O") > Cells(row_no, "P") Or Cells(row_no, "O") > Cells(row_no, "L") Then box = MsgBox("Row : " & row_no, 64, "Information")
    Next
End Sub

;)
 
Upvote 0
I appreciate your quick response.
I am having an issue with the Code.
When I tested the code on a simple spreadsheet comparing column A,B,C it worked perfectly. However, when I put the code into a more complicated spreadsheet it is not working.
Will the fact that cells "O4","P4" & "L4" are formulas make a difference?
 
Upvote 0
And this one ?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    For row_no = 1 To 30
        If Val(Cells(row_no, "O")) > Val(Cells(row_no, "P")) Or Val(Cells(row_no, "O")) > Val(Cells(row_no, "L")) Then box = MsgBox("Row : " & row_no, 64, "Information")
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,212
Messages
6,054,184
Members
444,707
Latest member
cahayagalax

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top