Henri would like to copy the data contained in a source cell to a destination cell without leaving the current position on the worksheet. In other words, he would like to copy from cell A1 to cell AE459 without leaving his current position at V104. He wonders if such an edit is even possible.
Of course, the obvious approach to this is to simply put the formula =A1 into cell AE459. Then, Excel takes care of making sure that the two cells are equal. You could also open a second window on the worksheet and take care of the copying within that window; the cell selected in the original window (cell V104) would remain unchanged.
If you actually want to do a "copy" operation, though, without opening a second window, then you'll need to resort to a macro.
Copying from one cell to another within a macro is rather easy. For instance, the following example will copy the contents of cell A1 to AE459 without affecting whatever cell you currently have selected:
Sub CopyCell1() ' Copy the cell value to destination cell Range("AE459") = Range("A1") End Sub
If you want to copy a formula that is in cell A1 to the destination, then you need to modify how the copy is done. Specifically, you need to use the Copy method using the destination range as a parameter.
Sub CopyCell2() ' Copy the relative formula to destination Range("A1").Copy Range("AE459") End Sub
Of course, a drawback of these macros is that they are static—they only copy from cell A1 to cell AE459. If your copying needs can vary, you may want to consider performing the task in the VB Editor's Immediate window. Just pop open the editor and type the single line from the appropriate macro into the window. The copying is then done and you can close the editor, all without affecting whatever cell you had selected.
Another way to provide a bit of flexibility into the source and destination for the macro is to have it (the macro) prompt the user for the source and destination. The following macro takes this approach.
Sub CopyCell3() Dim SrceCell As String Dim DestCell As String SrceCell = InputBox("Copy From Cell ...") DestCell = InputBox("Copy To Cell ...") Range(DestCell) = Range(SrceCell) End Sub
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9949) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
Want to select all the data in a contiguous section of a worksheet? The shortcut discussed in this tip makes it very easy.
Discover MoreExcel provides keyboard shortcuts for a variety of purposes. This tip examines two such shortcuts, designed to allow ...
Discover MoreWhen you cut and paste rows using Ctrl+X and Ctrl+V, Excel leaves empty the rows where the cut information was previously ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2015-04-21 12:02:19
Chris C
Thanks for the tip! FYI Micky, as a user who dabbles, I don't consider it a waste of ink because while the examples tend to be simple, they are good for learning how the concept works and then modifying it to fit my needs. Simply making one cell = another as you showed might be quicker but misses the big picture.
I do appreciate the comments that expand the basic code, such as using other worksheets and adding properties. Have a nice day!
2015-04-13 10:21:43
It may be just me, but saying
Range() = Range () looks ugly.
Better use the property you actually want to copy, like Range.Value or Range.Formula.
2015-04-12 10:39:04
Michael (Micky) Avidan
@Sam,
If you want to copy from Sheet1 to Sheet2 and the cursor rests within one of two worksheets - you can omit that sheets name.
Here are few examples - Check them out:
--------------------------------------
Sheets("Sheet2").[AE459] = Sheets("Sheet1").[A1]
Sheets("Sheet2").[AE459] = [A1]
[AE459] = Sheets("Sheet1").[A1]
--------------------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL
2015-04-11 08:39:39
Thanks for the shortcut, Micky. How about copying to another worksheet?
2015-04-11 05:19:37
Michael (Micky) Avidan
No need to waste so much ink:
[AE459] = [A1]
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments