ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving a range between sheets (https://www.excelbanter.com/excel-programming/285051-moving-range-between-sheets.html)

Jack

Moving a range between sheets
 
Hi
I'm using Excel 2003 and am trying to move a range from one sheet to another using VBA, but I am not having a great deal of luck. In a macro I can perform what I want with this code

Sheets("Customers").Select
Range("A16:I16").Select
Selection.Copy
Sheets("CheckIn").Select
Range("A5").Select
Selection.Paste

However I wish to do this by attaching code to the click event of a button rather than a macro, using the code from the Macro in the click event will bring up a runtime error 1004 'Select method of range class failed', the problem seems to be on the Range("A16:I16").Select line. Running the Macro works fine and the data is copied over.

Thanks for any information
Jack

Bill Manville

Moving a range between sheets
 
Jack wrote:
However I wish to do this by attaching code to the click event of a button rather than a macro,
using the code from the Macro in the click event will bring up a runtime error 1004
'Select method of range class failed',


Set the TakeFocusOnClick property of the button to False


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup



All times are GMT +1. The time now is 10:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com