
It also tends to be constant as you move across rows or columns. One very useful trick is FormulaR1C1 property of a range as this allows the formula to be set on multiple cells simultaneously. In this case, it needs to be a bit more of a bespoke build for the case. Unfortunately copying just the formats or formulas of the source range is a lot harder. Set Dest = ThisWorkbook.Names('Dest').RefersToRangeĭest.Columns(, colIdx).ColumnWidth = Src.Columns(, colIdx).ColumnWidth Set Src = ThisWorkbook.Names('Src').RefersToRange Set dest = ThisWorkbook.Names('dest').RefersToRangeĭest.Resize(, ).Value = src.ValueĬopying Column Width is easy enough as you just need to iterate over the columns and set each width individually. Set src = ThisWorkbook.Names('src').RefersToRange Please note, this only copies the values it does not copy any formatting. I resize the destination range to be the same side as the source and then can set the value of the cells via the Value property. The Range.Copy command takes a parameter of the target range to paste:Ĭopying values is a little more involved. To reproduce the behavior of the first version without using the clipboard is actually very straight forward. The different values can be found here, and the general documentation on PasteSpecial here. It is easy to amend so that values are pasted of just values by changing the xlPasteAll. The last line ‘ Application.CutCopyMode = false‘ clears the clipboard. Adding one extra line achieves copying the widths:īoth of these use the clipboard. This copies everything as is but doesn’t copy the column widths. Set dest = ThisWorkbook.Names('Dest').RefersToRange Set src = ThisWorkbook.Names('Src').RefersToRange One of the features that VBA allows is copying data without going through the clipboard.
#Copy data to office clipboard excel how to
The only one of these that needs any extra work is how to copy and paste data around a spread sheet. Again far too easy to muck up automation. Too easy for users to accidently be in wrong place. Never use the Active Cell, Sheet, Workbook or the Selection.
#Copy data to office clipboard excel code
Keeps the VBA code reasonably separate from the spread sheet layout.
