Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving data from one worksheet to another

Status
Not open for further replies.

lamaar

Technical User
Jun 29, 2000
392
GB
I have the following code on a button:

Columns("BA:BK").Select - select the range
Selection.Copy - copy it
Sheets("Results").Select - select a different worksheet
Range("A1").Select - select a range/cell
ActiveSheet.Paste - paste it

When I run this from tools - macro - run macro - it works fine
when I assign it to the button it errors , 1004 - select method of range class failed

Why? Lamaar75@hotmail.com
 
Hi,
I am not sure WHY, but many times Excel is looking for an Object -- in this case the ActiveSheet Ojbect.

So try this...
Code:
    ActiveSheet.Columns("BA:BK").Select '- select the range
    Selection.Copy ' - copy it
    Sheets("Results").Select '- select a different worksheet
    ActiveSheet.Range("A1").Select '- select a range/cell
    ActiveSheet.Paste '- paste it
Hopt this helps :) Skip,
metzgsk@voughtaircraft.com
 
lamaar,

Tested this, and it works...

Sub test()
Range("BA:BK").Select '- select the range
Selection.Copy ' - copy it
Worksheets("Results").Select '- select a different worksheet
ActiveSheet.Range("A1").Select '- select a range/cell
ActiveSheet.Paste '- paste it
End Sub

Please confirm that it works for you.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca

 
I'm not too familiar with VBA but wouldn't this code do the same trick?? if not explain the difference.

Sheet1
CELL A1 = Hello


Sheet2
CELL A1 code ='sheet1'!a1


 
this, in fact, does work
Code:
Sheet1.Activate
Cells(1.1).Value = "Hello"

Sheet2.Activate
Cells(1, 1).Value = Sheet1.Cells(1.1).Value
Skip,
metzgsk@voughtaircraft.com
 
Thanks to all - I have successfully inmplemented the above and will award everyone a star for their input.

Thanks

Lamaar Lamaar75@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top