Can I replace blocks of data within an array rather than looping thru it.

MrTeeny

Board Regular
Joined
Jul 26, 2017
Messages
238
If I grab a block of data from excel into an array say A1:E5, is there anyway I can simply reference the data in the region B1:E5, I'd simply like to replace that section with the data from A1:D5.

If is was doing it on the sheet it'd simply be

VBA Code:
Range("B1:E5").Value = Range("A1:D5").Value

but I'm stumped as how to reference it within the array.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
It looks to me like you are just moving the whole data set over one column.
Can you just insert a blank column in column A? Or is there data below it that should not move?
If that is the case, why not just use Cut/Paste instead?
 
Upvote 0
The Cut/Paste option would just look like:
VBA Code:
    Range("A1:D5").Cut Range("B1")
 
Upvote 0
I'm basically doing an audit trail of the last few cells, I could do it by simply shifting the cells along one clipping off the last row and dumping new data into the first column but was hoping to do all calculations etc in an array and then just do one dump of data back to the sheet rather than lots of writing of cells to the sheet.
 
Upvote 0
I'm basically doing an audit trail of the last few cells, I could do it by simply shifting the cells along one clipping off the last row and dumping new data into the first column but was hoping to do all calculations etc in an array and then just do one dump of data back to the sheet rather than lots of writing of cells to the sheet.
In order to do that, you would need to do the something like the following in your VBA code:
1. Create an array
2. Iterate through the array and apply each calculation and store the result
3. Iterate through the array again, and populate each cell in your range
 
Upvote 0
Solution
Thanks, so it looks like you can't amend subsets of data within the array in one go, guess I'll have to loop thru and amend each item in the array separately if that's the case or maybe just shift the data A1:D5 to B1:E5 and do the new calcs on column A in an array so that can be dumped in one go to the sheet rather than each cell updated one at a time.

Thanks again
 
Upvote 0
Thanks, so it looks like you can't amend subsets of data within the array in one go, guess I'll have to loop thru and amend each item in the array separately if that's the case.
Arrays are not my forte (so I may be mistaken), but I believe that is the case. I believe each item of the array needs to be set explicitly.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

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