ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Excel VBA (https://www.excelbanter.com/excel-discussion-misc-queries/259418-excel-vba.html)

Mel[_2_]

Excel VBA
 
I am trying to create a command button so that when a user clicks on the
command button a message box pops up with the the answer to 2 cells added
together
--
Mel

Gord Dibben

Excel VBA
 
Added as in Summed like =A1+B1

Or added like =A1 & B1

Go with the first one.

Create a Command Button with this code

Private Sub CommandButton1_Click()
Dim rng As Range
Set rng = ActiveSheet.Range("A1:B1")
MsgBox "sum of A1 and B1 is " & Application.WorksheetFunction.Sum(rng)
End Sub

No error trapping.


Gord Dibben MS Excel MVP



On Fri, 19 Mar 2010 16:02:01 -0700, Mel wrote:

I am trying to create a command button so that when a user clicks on the
command button a message box pops up with the the answer to 2 cells added
together



Dave O

Excel VBA
 
The code looks like this:

sub Sum_of_two_cells()
msgbox range("a1").value + range("b1").value
end sub

You can use the Control Toolbox on the Visual Basic toolbar to assign
the macro to a button; I prefer to click (on the Excel menu) View
Toolbars Forms and use the command button from that toolbar.


Good luck with it!
Dave O
Eschew obfuscation


All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com