Message box that displays content of different cell than the cell that triggered the messagebox

HJA14

Board Regular
Joined
Apr 12, 2016
Messages
60
Dear all,

I would like to get your help with constructing my module. The idea of the module is that when a certain condition is satisfied a message box appears. This messagebox needs to display the name of the sheet, the content (value) of the cell that triggered the messagebox and the content of the cell that is located 3 columns to the left of the trigger cell.

Code:
Sub Workbook_SheetCalculate(ByVal Sh As Object)Dim myRange As Range
Dim myArray as Variant
Set myRange As Sh.Range("N1:N50,AA1:AA50,AN1:AN50,BA1:BA50,BN1:BN50,CA1:CA50")
myArray = myRange.Cells
    Dim product as Double
product = Sh.Range("A1").Value * Sh.Range("A2").Value
Dim n As Long
For n = 1 To Ubound	(myArray)
If myArray(n,1) > product Then
		MsgBox ...

Ideally I would like the message box to display the following:

"Ticker: (Name of the sheet). ABCDEFGH in the ... (...1= cell 3 columns to the left of target cell that triggers message box) is ... (...2 = content of cell that triggers message box) ABCDEF."

So far, the code of the message box looks like this:

Code:
MsgBox "Ticker: " & Sh.Name & " . ABCDEFGH in the " &  ...1 &  "is  " &myRange.Cells(n).Address & " ABCDEF."

How do include the cell that is located 3 columns to the left of the target cell in the messagebox?

Thank you very much
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Possibly...
Code:
Sub Workbook_SheetCalculate(ByVal Sh As Worksheet)
    Dim myRange          As Range
    Dim product          As Double
    Dim n                As Long

    Set myRange = Sh.Range("N1:N50,AA1:AA50,AN1:AN50,BA1:BA50,BN1:BN50,CA1:CA50")
    product = Sh.Range("A1").Value * Sh.Range("A2").Value
    For n = 1 To myRange.Count
        If myRange(n) > product Then
            MsgBox "Ticker: " & Sh.Name & ". ABCDEFGH in the ... " & myRange(n).Offset(, -3).Value & " is ... " & myRange(n) & " ABCDEF."
        End If
    Next n
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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