anyone knows how to solve?

BewilderedSoul

New Member
Joined
Apr 22, 2011
Messages
6
Hi, I'm running the following macro at home.xlsm. The msgbox will show me the value generated by the MySubtotal method. However, I want the results to be pasted to one of the cells in home.xlsm. Can it be done?
Code:
Sub total()
Dim MySelection As Range
Dim MySubtotal As Double
Windows("book1.xls").Activate
 
 
Set MySelection = Application.InputBox(Prompt:="Select a range of cells", Type:=8)
 
MySubtotal = Application.WorksheetFunction.Subtotal(9, Worksheets("Sheet1").Range(MySelection.Address))
 
Windows("home.xlsm").Activate
 
 
    MsgBox MySubtotal
 
 
        End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Maybe like this

Code:
Sub total()
Dim MySelection As Range
Dim MySubtotal As Double
Windows("book1.xls").Activate
 
 
Set MySelection = Application.InputBox(Prompt:="Select a range of cells", Type:=8)
 
MySubtotal = Application.WorksheetFunction.Subtotal(9, Worksheets("Sheet1").Range(MySelection.Address))
 
Workbooks("home.xlsm").Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1).Value = MySubtotal
 
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,575
Messages
6,179,637
Members
452,934
Latest member
Jdsonne31

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