Option Explicit
Sub CalculationOnSelctionRng()
On Error GoTo Last
Dim Rng As Range, sArea As Variant, fCell As Variant, lCell As Variant, ACellAdd As String, fCellAdd As String, lCellAdd As String, NoOfCell As Integer
Dim CRightUp As Variant, CLeftDown As Variant, CRightUpAdd As Variant, CLeftDownAdd As Variant
Set Rng = Selection
sArea = Rng.Address(0, 0)
fCell = Rng.Cells(1).Value
lCell = Rng(Rng.count).Value
ACellAdd = ActiveCell.Address(0, 0)
fCellAdd = Rng.Cells(1).Address(0, 0)
lCellAdd = Rng(Rng.count).Address(0, 0)
NoOfCell = Range(Rng.Address).count
CRightUp = Rng.Cells(1, Rng.Columns.count)
CLeftDown = Rng.Cells(Rng.Rows.count, 1)
CRightUpAdd = Rng.Cells(1, Rng.Columns.count).Address(0, 0)
CLeftDownAdd = Rng.Cells(Rng.Rows.count, 1).Address(0, 0)
If ACellAdd = lCellAdd And IsNumeric(fCell) And IsNumeric(lCell) And fCell <> 0 And lCell <> 0 Then
MsgBox "Range " & vbTab & "= " & sArea & vbCr & _
"Cells" & vbTab & "= " & lCellAdd & " & " & fCellAdd & vbCr & vbCr & _
"Subtract" & vbTab & "= " & lCell - fCell & vbCr & _
"Multiple" & vbTab & "= " & lCell * fCell & vbCr & _
"Divide " & vbTab & "= " & lCell / fCell & vbCr & _
"Sum " & vbTab & "= " & lCell + fCell & vbCr
ElseIf ACellAdd = fCellAdd And IsNumeric(fCell) And IsNumeric(lCell) And fCell <> 0 And lCell <> 0 Then
MsgBox "Range " & vbTab & "= " & sArea & vbCr & _
"Cells" & vbTab & "= " & fCellAdd & " & " & lCellAdd & vbCr & vbCr & _
"Subtract" & vbTab & "= " & fCell - lCell & vbCr & _
"Multiple" & vbTab & "= " & fCell * lCell & vbCr & _
"Divide " & vbTab & "= " & fCell / lCell & vbCr & _
"Sum " & vbTab & "= " & fCell + lCell & vbCr
ElseIf ACellAdd = CLeftDownAdd And IsNumeric(CLeftDown) And IsNumeric(CRightUp) And CLeftDown <> 0 And CRightUp <> 0 Then
MsgBox "Range " & vbTab & "= " & sArea & vbCr & _
"Cells" & vbTab & "= " & CLeftDownAdd & " & " & CRightUpAdd & vbCr & vbCr & _
"Subtract" & vbTab & "= " & CLeftDown - CRightUp & vbCr & _
"Multiple" & vbTab & "= " & CLeftDown * CRightUp & vbCr & _
"Divide " & vbTab & "= " & CLeftDown / CRightUp & vbCr & _
"Sum " & vbTab & "= " & CLeftDown + CRightUp & vbCr
ElseIf ACellAdd = CRightUpAdd And IsNumeric(CLeftDown) And IsNumeric(CRightUp) And CLeftDown <> 0 And CRightUp <> 0 Then
MsgBox "Range " & vbTab & "= " & sArea & vbCr & _
"Cells" & vbTab & "= " & CRightUpAdd & " & " & CLeftDownAdd & vbCr & vbCr & _
"Subtract" & vbTab & "= " & CRightUp - CLeftDown & vbCr & _
"Multiple" & vbTab & "= " & CRightUp * CLeftDown & vbCr & _
"Divide " & vbTab & "= " & CRightUp / CLeftDown & vbCr & _
"Sum " & vbTab & "= " & CRightUp + CLeftDown & vbCr
Else
MsgBox "The values in SELECTION is not number or the last cell is equal to 0"
End If
Last: Exit Sub
End Sub