Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Monday, March 13, 2017 at 9:24:48 PM UTC-7, GS wrote:
You do not need this line... Option Base 0 ..because arrays are zero-based by default! One way using arrays: Sub Copy_Array() 'Do not dimension variants you'll be assigning ranges to! Dim vaSrc, vaTgt, vTmp, n& '(As Long) 'Size your ranges as contiguous vaSrc = Range("F1:F5"): vaTgt = Range("A1:E5") 'Replace vaSrc data only in vaTgt For n = LBound(vaSrc) To UBound(vaSrc) vaTgt(n, n) = vaSrc(n, 1) Next 'n 'Assign vaTgt to its range Range("A1:E5") = vaTgt End Sub Another way: Sub Copy_RngToAreas() Dim vaSrc, rngTgt As Range, n& '(as long type) vaSrc = Range("F1:F5") Set rngTgt = Range("A1,B2,C3,D4,E5") 'Replace vaSrc data only in rngTgt For n = LBound(vaSrc) To UBound(vaSrc) rngTgt(n, n) = vaSrc(n, 1) Next 'n End Sub -- Thanks, Garry, those work pretty snappy. I used the diagonal A1 to E5 to represent what I thought to be 'scattered cells, which are contiguous cells, I think...? Is there a way to copy F1:F5 cells to cells A1, D5, H9, J6, M11, where these are truly 'scattered'? And a way to copy say, five truly scattered cells to five other truly scattered cells? Howard |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Scattered array cells copy to scattered array cells another workbook | Excel Programming | |||
Reading variable list of cells into array | Excel Programming | |||
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) | Excel Programming | |||
combining cells and array from different sheets into an array to pass to IRR() | Excel Discussion (Misc queries) | |||
Writing Range to Array | Excel Programming |