Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default ActiveSheet.Name?

Hi all,

I have the following macro that sums any cells that I select:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String

str = Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub

The macro works fine but I would like to be able to paste the result into
another worksheet. At the moment if I say select cells A1 and B1, the result
would be "=sum($A$1,$B$1)" when I hit paste. When I go to the next worksheet
and paste, the resulting formula obviously doesnąt work as the cell
references do not include the original sheet name.

Ive tried adding ActiveSheet.Name to the macro but I couldnąt work out how
to add the sheet name before each cell I selected.

Any help greatly appreciated.

Andrew.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default ActiveSheet.Name?

A better solution is

Sub CopySum()
Dim Arr As Variant
Dim N As Long
Dim MyDataObj As New DataObject
Dim str As String
Arr = Split(Selection.Address, ",")
For N = LBound(Arr) To UBound(Arr)
str = str & "," & Selection.Worksheet.Name & "!" & Arr(N)
Next N
str = Mid(str, 2)
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
Andrew,

Try the following:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String
str = Selection.Worksheet.Name & "!" & Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Andrew Stedman" wrote in message
...
Hi all,

I have the following macro that sums any cells that I select:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String

str = Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub

The macro works fine but I would like to be able to paste the

result into
another worksheet. At the moment if I say select cells A1 and

B1, the result
would be "=sum($A$1,$B$1)" when I hit paste. When I go to the

next worksheet
and paste, the resulting formula obviously doesnąt work as the

cell
references do not include the original sheet name.

Ive tried adding ActiveSheet.Name to the macro but I couldnąt

work out how
to add the sheet name before each cell I selected.

Any help greatly appreciated.

Andrew.






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default ActiveSheet.Name?

Chip I entered your code (below);
I then enter figures (random numbers) in cells C6:C10, then selected them
(that is highlighted them)
and ran the code: Instantly, I got a Compile error: User-defined type not
defined
with the this line (#4) highlighted.

MyDataObj As New DataObject

What have I failed to do?
TIA,

"Chip Pearson" wrote in message
...
A better solution is

Sub CopySum()
Dim Arr As Variant
Dim N As Long
Dim MyDataObj As New DataObject
Dim str As String
Arr = Split(Selection.Address, ",")
For N = LBound(Arr) To UBound(Arr)
str = str & "," & Selection.Worksheet.Name & "!" & Arr(N)
Next N
str = Mid(str, 2)
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
Andrew,

Try the following:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String
str = Selection.Worksheet.Name & "!" & Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Andrew Stedman" wrote in message
...
Hi all,

I have the following macro that sums any cells that I select:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String

str = Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub

The macro works fine but I would like to be able to paste the

result into
another worksheet. At the moment if I say select cells A1 and

B1, the result
would be "=sum($A$1,$B$1)" when I hit paste. When I go to the

next worksheet
and paste, the resulting formula obviously doesnąt work as the

cell
references do not include the original sheet name.

Ive tried adding ActiveSheet.Name to the macro but I couldnąt

work out how
to add the sheet name before each cell I selected.

Any help greatly appreciated.

Andrew.








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default ActiveSheet.Name?

You need to add a reference to the MSForms object library, which
is where the DataObject object is defined. In VBA, go to the
Tools menu and choose References. There, scroll down to
"Microsoft Forms 2.0 Object Library" and put a check in the box
next to it.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"JMay" wrote in message
news:anSUa.3258$le.124@lakeread06...
Chip I entered your code (below);
I then enter figures (random numbers) in cells C6:C10, then

selected them
(that is highlighted them)
and ran the code: Instantly, I got a Compile error:

User-defined type not
defined
with the this line (#4) highlighted.

MyDataObj As New DataObject

What have I failed to do?
TIA,

"Chip Pearson" wrote in message
...
A better solution is

Sub CopySum()
Dim Arr As Variant
Dim N As Long
Dim MyDataObj As New DataObject
Dim str As String
Arr = Split(Selection.Address, ",")
For N = LBound(Arr) To UBound(Arr)
str = str & "," & Selection.Worksheet.Name & "!" &

Arr(N)
Next N
str = Mid(str, 2)
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
Andrew,

Try the following:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String
str = Selection.Worksheet.Name & "!" & Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Andrew Stedman" wrote in message
...
Hi all,

I have the following macro that sums any cells that I

select:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String

str = Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub

The macro works fine but I would like to be able to paste

the
result into
another worksheet. At the moment if I say select cells A1

and
B1, the result
would be "=sum($A$1,$B$1)" when I hit paste. When I go to

the
next worksheet
and paste, the resulting formula obviously doesnąt work as

the
cell
references do not include the original sheet name.

Ive tried adding ActiveSheet.Name to the macro but I

couldnąt
work out how
to add the sheet name before each cell I selected.

Any help greatly appreciated.

Andrew.










  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default ActiveSheet.Name?

appreciate the help; Got it working!! Don't quiet understand though what
"Forms" has to do with "what seems to be" normal spreadsheet/vba stuff...

"Chip Pearson" wrote in message
...
You need to add a reference to the MSForms object library, which
is where the DataObject object is defined. In VBA, go to the
Tools menu and choose References. There, scroll down to
"Microsoft Forms 2.0 Object Library" and put a check in the box
next to it.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"JMay" wrote in message
news:anSUa.3258$le.124@lakeread06...
Chip I entered your code (below);
I then enter figures (random numbers) in cells C6:C10, then

selected them
(that is highlighted them)
and ran the code: Instantly, I got a Compile error:

User-defined type not
defined
with the this line (#4) highlighted.

MyDataObj As New DataObject

What have I failed to do?
TIA,

"Chip Pearson" wrote in message
...
A better solution is

Sub CopySum()
Dim Arr As Variant
Dim N As Long
Dim MyDataObj As New DataObject
Dim str As String
Arr = Split(Selection.Address, ",")
For N = LBound(Arr) To UBound(Arr)
str = str & "," & Selection.Worksheet.Name & "!" &

Arr(N)
Next N
str = Mid(str, 2)
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
Andrew,

Try the following:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String
str = Selection.Worksheet.Name & "!" & Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Andrew Stedman" wrote in message
...
Hi all,

I have the following macro that sums any cells that I

select:

Sub CopySum()
Dim MyDataObj As New DataObject
Dim str As String

str = Selection.Address
MyDataObj.SetText "=sum(" & str & ")"
MyDataObj.PutInClipboard
End Sub

The macro works fine but I would like to be able to paste

the
result into
another worksheet. At the moment if I say select cells A1

and
B1, the result
would be "=sum($A$1,$B$1)" when I hit paste. When I go to

the
next worksheet
and paste, the resulting formula obviously doesnąt work as

the
cell
references do not include the original sheet name.

Ive tried adding ActiveSheet.Name to the macro but I

couldnąt
work out how
to add the sheet name before each cell I selected.

Any help greatly appreciated.

Andrew.














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
Select the ActiveSheet & the sheet next to it Dolphinv4 Excel Discussion (Misc queries) 1 December 11th 07 02:13 PM
Can't get ActiveSheet to work... [email protected] Excel Discussion (Misc queries) 2 August 16th 07 06:12 PM
ActiveSheet.Paste (error) Puzzled Excel Worksheet Functions 1 August 2nd 07 06:18 PM
ActiveCell or ActiveSheet Launchnet Excel Worksheet Functions 1 July 20th 07 07:46 PM
ActiveSheet.Paste - Error help? dk_ Excel Discussion (Misc queries) 4 November 20th 06 12:27 AM


All times are GMT +1. The time now is 01:39 AM.

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"