Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Easier Method

I have the following macro that is assigned to a button on the formatting bar.

Note: The macro is in a different file than the file where the cells are
selected.

Sub SumSelectedCells()
Application.ScreenUpdating = False
Dim wb As Workbook
Set wb = ActiveWorkbook
wb.Activate
myVar = InputBox("Enter Cell Location", "Create Variable")
Range(myVar).Value =
Application.WorksheetFunction.Sum(Application.Sele ction)
Windows("zCalc.xls").Close (0)
Application.ScreenUpdating = True
End Sub

So what this does is if I have cells highlighted in a file and I want to get
the sum in a cell I click on the button to run this macro. The only thing is
I have to input a cell location for the macro to put the value. How can I do
this without having to input a cell address. The ideal would be : I
highlight the cells ; click to run the macro ; then click in a cell and paste
.... or something like that .

Thank you ,

Steven

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default Easier Method

Hi Steven,

Try something like:

'==========
Public SumSelectedCells()
Dim mySum As Double
Dim Rng As Range

mySum = Application.Sum(Selection)

On Error Resume Next
Set Rng = Application.InputBox( _
Prompt:="Selectation cell", _
Title:="Sum Cell", _
Type:=8)
On Error GoTo 0

If Not Rng Is Nothing Then
Rng.Cells(1).Value = mySum
End If
End Sub
'<<==========



---
Regards.
Norman

"Steven" wrote in message
...
I have the following macro that is assigned to a button on the formatting
bar.

Note: The macro is in a different file than the file where the cells are
selected.

Sub SumSelectedCells()
Application.ScreenUpdating = False
Dim wb As Workbook
Set wb = ActiveWorkbook
wb.Activate
myVar = InputBox("Enter Cell Location", "Create Variable")
Range(myVar).Value =
Application.WorksheetFunction.Sum(Application.Sele ction)
Windows("zCalc.xls").Close (0)
Application.ScreenUpdating = True
End Sub

So what this does is if I have cells highlighted in a file and I want to
get
the sum in a cell I click on the button to run this macro. The only thing
is
I have to input a cell location for the macro to put the value. How can I
do
this without having to input a cell address. The ideal would be : I
highlight the cells ; click to run the macro ; then click in a cell and
paste
... or something like that .

Thank you ,

Steven


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default Easier Method

Hi Steven,

There is a sdignificant typo in my
suggested code.

Public SumSelectedCells()


Should read:

Public Sub SumSelectedCells()



---
Regards.
Norman
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
easier method for inserting object in cell Radhakant Panigrahi Excel Discussion (Misc queries) 0 April 22nd 10 03:59 PM
Please post this thread a correct full method, method about Nast Runsome New Users to Excel 8 February 25th 08 03:29 PM
Please post this thread a complete correct method, method about te Nast Runsome New Users to Excel 0 February 23rd 08 09:42 PM
GetObject method not work after Call Shell Method ben Excel Programming 8 February 21st 06 03:45 PM
There has to be any easier way!! mully New Users to Excel 18 August 13th 05 12:26 PM


All times are GMT +1. The time now is 06:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"