Share via

Display difference between two numbers in excel status bar.

Anonymous
2012-12-19T06:11:21+00:00

Hi,

Is there a way to display difference between two numbers in excel status bar?. Right now, I see sum, max, min, avg etc  in excel status bar, but was wondering if it is possible to display the difference.

 I will be selecting the two cells and based on the selection , the status bar should display the difference between 1st and 2nd selection.

Thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-12-19T12:15:51+00:00

Thanks Pavan.

 But, I would like to select any two cells and need not be in A1 or B1 .

Hi,

Right click the sheet tab, view code and paste this in and close VB editor.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Selection.Cells.Count = 2 Then

   On Error Resume Next

    If WorksheetFunction.Count(Range(Selection.Address)) = 2 Then

        Application.StatusBar = "The difference is " & _

        WorksheetFunction.Max(Range(Selection.Address)) _

        - WorksheetFunction.Min(Range(Selection.Address))

    Else

        Application.StatusBar = "The difference is " & _

        WorksheetFunction.Max(Range(Selection.Address))

    End If

Else

    Application.StatusBar = False

End If

End Sub

Was this answer helpful?

20+ people found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2012-12-19T10:43:44+00:00

Hi friend

  • Use ALT+F11 keys altogether
  • This will open your code editor window
  • Assuming that value1 is to be pasted on cell A1 and value2  to be pasted on cell B1, then paste the folllowing code in the window:

Sub Worksheet_SelectionChange(ByVal Target As Range)

a = Range("A1").Value

b = Range("B1").Value

c = a - b

Application.StatusBar = "The difference is " & c

End Sub

  • Now, put any number in cellA1 and any number in cell B1, and then see the status bar.
  • Here you are done.

Let me know if this worked for you. You can mark this as your answer/helpful reply, if you wish so.

Many thanks

Pawan Kumar

Was this answer helpful?

4 people found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-12-20T06:41:23+00:00

    Thank you very much Mike H

    Btw, What I needed is was the difference between 1st cell and the second cell i.e., the difference should also show up negative numbers and not just difference between max and min.

    I made slight modifications in VBA code (added an array to pass the contents of range and calculate the difference ) given below which is working per my expectations.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim Arr(1 To 2) As Variant

    Dim r as Range

    If Selection.Cells.Count = 2 Then

    On Error Resume Next

    If WorksheetFunction.Count(Range(Selection.Address)) = 2 Then

    c = ActiveWindow.RangeSelection.Address

    For i = 1 To 2

    For Each r In Range(c).Cells

    Arr(i) = r.Value

    i = i + 1

    Next r

    Next i

    Application.StatusBar = " The difference is " & Arr(1) - Arr(2)

    Else

    Application.StatusBar = "The difference is " & _

    WorksheetFunction.Max(Range(Selection.Address))

    End If

    Else

    Application.StatusBar = False

    End If

    End Sub

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-11-12T09:39:17+00:00

    Thanks Pavan.

     But, I would like to select any two cells and need not be in A1 or B1 .

    Hi,

     

    Right click the sheet tab, view code and paste this in and close VB editor.

     

     

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Selection.Cells.Count = 2 Then

       On Error Resume Next

        If WorksheetFunction.Count(Range(Selection.Address)) = 2 Then

            Application.StatusBar = "The difference is " & _

            WorksheetFunction.Max(Range(Selection.Address)) _

            - WorksheetFunction.Min(Range(Selection.Address))

        Else

            Application.StatusBar = "The difference is " & _

            WorksheetFunction.Max(Range(Selection.Address))

        End If

    Else

        Application.StatusBar = False

    End If

    End Sub

    Hello

    Is it possible to make this code work in any workpaper?

    Thanks

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-12-19T11:37:31+00:00

    Thanks Pavan.

     But, I would like to select any two cells and need not be in A1 or B1 .

    Was this answer helpful?

    0 comments No comments