简体   繁体   中英

Printing array to variable cell range VBA

I have a variable array which I want to print into another workbook range. As I loop through separate arrays and secondary workbooks, the cell I want to print to will change.

Some sheets will need to array to be printed to A6:N, some will need the array printed to A300:N etc. I want to get to the bottom of the list of existing data and 'paste' the array below it.

Here is what I have so far:

bottomrow2 = Range("A9999").End(xlUp).Row
Set PasteCell = ClientBook.Sheets("PasteSheet").Range(Cells(bottomrow2 + 1,1),Cells(bottomrow2 + 1, 14))
Range(PasteCell & UBound(array)) = array

PasteCell is effectively trying to be my A1:N. It's worth noting that if I hard-code where to paste the array to, it works fine.

Range("A1:N" & UBound(array)) = array
'^This works fine.

Thanks for any help you can give.

You need to resize Paste Cell, so

Set PasteCell=PasteCell.Resize(ubound(array),14)

something like that. Or just use the anchor cell maybe, set paste cell to just be bottomrow2,1 ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM