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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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