Active Sheet, a must to copy and paste?

Alive

New Member
Joined
Sep 30, 2011
Messages
8
Hi,

A very stupid but annoying question. I am just copying a cell to another. But it works only when Sheet1 was the active one, or an error happens. I didn't get it. Did I type in something wrong? Thanks in advance.


Sub test()

For xx = 1 To 5

Workbooks("Circular v2.xlsx").Sheets("Sheet1").Range(Cells((1 + xx), 1), Cells((1 + xx), 1)).Copy _
Workbooks("Circular v2.xlsx").Sheets("Sheet2").Range("F20")

Next xx

End Sub
 
Hi Jim,

Thanks for your posting, which helped me understand the codes further.



Great topic -- there's not enough said about this to beginners of VBA - so thanks Cindy

only to ADD to the thread..
The culprit in the OP's line one code is (IN RED BELOW)

Workbooks("Circular v2.xlsx").Sheets("Sheet1").Range(Cells((1 + xx), 1), Cells((1 + xx), 1)).Copy
Right?

and also, not sure I'm fully understanding (?) your comment:
edit: Note that if you use .xlsx as shown in the above code, you can't save the macro in the workbook. Could you clarify?

Jim
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Thanks! Efficiency is always of importance.




If you are just copying one cell.
Code:
Workbooks("Circular v2.xlsx").Sheets("Sheet1").Cells(1 + xx, 1).Copy _
Workbooks("Circular v2.xlsx").Sheets("Sheet2").Range("F20")
 
Upvote 0
I don't think a book would teach you this, but I'm not sure a book would actually use syntax like that to copy a single cell.

Even if it was more than one cell you can probably still use Resize (and Offset?) to get the right range rather than Range(Cells, Cells).
 
Upvote 0
Thanks, also could I know where did you learn this? I am reading a book about vba programming, but it seems not help me on this issue...
That particular bit I learned here on the forum...I browse questions and answers randomly, and try to learn from other users.
In general, I learned VBA by having a project that I really wanted to automate (being of the belief that computers are better than I am at doing repetitive tasks). I tried record and playback a few times, then went to VBA help (sometimes helpful, sometimes not) to find bits and pieces I could modify.
I eventually found the Mr. Excel forum, and often try to answer questions that I don't really know the answer to, just to learn a bit more that may come in handy for one of my own projects in the future.
Cindy
 
Upvote 0
You are right, I changed the codes from the book and didn't realize the fault. Thanks.


I don't think a book would teach you this, but I'm not sure a book would actually use syntax like that to copy a single cell.

Even if it was more than one cell you can probably still use Resize (and Offset?) to get the right range rather than Range(Cells, Cells).
 
Upvote 0
Thanks for sharing your valuable experience! It seems that I will come here frequently to learn more.



That particular bit I learned here on the forum...I browse questions and answers randomly, and try to learn from other users.
In general, I learned VBA by having a project that I really wanted to automate (being of the belief that computers are better than I am at doing repetitive tasks). I tried record and playback a few times, then went to VBA help (sometimes helpful, sometimes not) to find bits and pieces I could modify.
I eventually found the Mr. Excel forum, and often try to answer questions that I don't really know the answer to, just to learn a bit more that may come in handy for one of my own projects in the future.
Cindy
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,233
Members
453,152
Latest member
ChrisMd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top