#1   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default vba error

Please help, I need this code to work.

The msgbox is fine but I need it on paer and in other
cells but it will not copy

Only the copy command fails, the other code works ok.


Sub Macro1()

'cell c6 contains the text "This bit"
myvar = Range("C6").Text
Selection.Copy
mytext = myvar & " Works " & Trim$(215) & " days each year"
MsgBox mytext

' I want to copy the string mytext into clipboard
mytext.Copy
' but that command fails

Range("D15").Select
ActiveSheet.Paste

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default vba error

Hi
you can't use the copy method on string variables. Allowed are only
objects (as range or worksheet objects)

--
Regards
Frank Kabel
Frankfurt, Germany


Tom wrote:
Please help, I need this code to work.

The msgbox is fine but I need it on paer and in other
cells but it will not copy

Only the copy command fails, the other code works ok.


Sub Macro1()

'cell c6 contains the text "This bit"
myvar = Range("C6").Text
Selection.Copy
mytext = myvar & " Works " & Trim$(215) & " days each year"
MsgBox mytext

' I want to copy the string mytext into clipboard
mytext.Copy
' but that command fails

Range("D15").Select
ActiveSheet.Paste

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default vba error

Tom

why copy and paste ?

Range("D15") = mytext ' should do what you want

A string doesn't have a copy method AFAIK.

Regards

Trevor


"Tom" wrote in message
...
Please help, I need this code to work.

The msgbox is fine but I need it on paer and in other
cells but it will not copy

Only the copy command fails, the other code works ok.


Sub Macro1()

'cell c6 contains the text "This bit"
myvar = Range("C6").Text
Selection.Copy
mytext = myvar & " Works " & Trim$(215) & " days each year"
MsgBox mytext

' I want to copy the string mytext into clipboard
mytext.Copy
' but that command fails

Range("D15").Select
ActiveSheet.Paste

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default vba error


-----Original Message-----
Tom

why copy and paste ?


what I need is to make a load of calculations and produce
a piece of text based on some fields in an Excel sheet. I
need to store this as a Macro so that it runs on the sheet
(which is replaced every hour) and the user can get a
report on the current figures.

I have it working as a msgbox, but I need to print it so I
thought the best way/ only way, was to stick it in a cell
and print that range. Due to network restricions I can not
use a VB program so it needs to ba an Excel macro.

It is not as simple as "the contents of one cell" into
another, it is "the result of some code" going into a cell.

If you can think of a way to print the contents of amsgbox
I'd be as happy as a pig in that stuff that pigs are happy
in.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default vba error

Hi

Sub Macro1()
Dim myvar As String, mytext As String
'cell c6 contains the text "This bit"
myvar = Range("C6").Text
mytext = myvar & " Works " & Trim$(215) & " days each year"
Range("D15").Value = mytext
End Sub

This is the implemented & tested solution that Trevor gave you. Test run
before assuming that your helpers misunderstood everything.

However, you are using the spreadsheet just as a mean to get to the printer
? You could use a userform instead. In the VB editor, Insert Userform. Put
a single Label onto it -it should by default be named Label1. Then run this:

Sub Macro2()
Dim myvar As String, mytext As String
'cell c6 contains the text "This bit"
myvar = Range("C6").Text
mytext = myvar & " Works " & Trim$(215) & " days each year"
UserForm1.Label1.Caption = mytext
DoEvents
UserForm1.PrintForm
DoEvents
Unload UserForm1
End Sub

HTH. Best wishes Harald

skrev i melding
...

-----Original Message-----
Tom

why copy and paste ?


what I need is to make a load of calculations and produce
a piece of text based on some fields in an Excel sheet. I
need to store this as a Macro so that it runs on the sheet
(which is replaced every hour) and the user can get a
report on the current figures.

I have it working as a msgbox, but I need to print it so I
thought the best way/ only way, was to stick it in a cell
and print that range. Due to network restricions I can not
use a VB program so it needs to ba an Excel macro.

It is not as simple as "the contents of one cell" into
another, it is "the result of some code" going into a cell.

If you can think of a way to print the contents of amsgbox
I'd be as happy as a pig in that stuff that pigs are happy
in.






  #6   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default I am an Arse.

Trevor & Harald,

Thank you both very much.

This works for me and I am so sorry I did not fully
explore the solution before reposting. I could make
excuses like it was late and I thought I would try to
scrape up a response while I was sleeping, but I should
have tested it before posting anything else.

I am now exploring the use of the Userform. This is
driving me nuts as I do all my stuff in VB6 but this
problem has to be resolved in Excel. I may well be back to
ask more questions later.

Thanks again for your assistance and patience.

Tom
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default vba error

Enter the following formula in cell "D15":
=C6 & " Works 215 days each year"

This technique also works well when you need to display messages on a chart,
since Excel won't let you build formulas on a chart (a string must simply be
a reference to a single cell on a worksheet somewhere).
--
Regards,
Bill


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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
I have Error 1919 Error Configuring ODBC dataSource Database Texanna1 Excel Discussion (Misc queries) 1 September 12th 06 06:35 AM
Error 50290: Error writing to Worksheet while using an ActiveX Control emblair3 Excel Programming 3 February 24th 04 06:03 PM


All times are GMT +1. The time now is 02:09 PM.

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

About Us

"It's about Microsoft Excel"