I need to write a lot of strings into a lot of cells quickly.
Here is the code I am currently using
Sub CopyArrayToWorksheet(myarray() As String, myworksheet As Worksheet, ArrayStart As Long, ArrayEnd As Long, SheetFirstRow As Long)
If SheetFirstRow = -1 Then SheetFirstRow = GetLastRow(myworksheet) + 1
myworksheet.Cells(1, 1).Select
Dim x As Long, y As Long
Application.ScreenUpdating = False
For x = ArrayStart To ArrayEnd
For y = LBound(myarray, 2) To UBound(myarray, 2)
'myworksheet.Cells(SheetFirstRow, y + 1).NumberFormat = "@"
myworksheet.Cells(SheetFirstRow, y + 1) = myarray(x, y)
Next y
SheetFirstRow = SheetFirstRow + 1
Next x
Application.ScreenUpdating = True
End Sub
This works, this used the be fast yesterday, it would write about 30'000 cells in a few seconds and now it takes minutes ! Nothing has changed but alas I cannot find what is wrong.
The reason why my data is in a 2 dimension string array is that it was easier and faster for me to perform operations on an array first and I really prefer it that way.
I searched before this and got found to try the Cells(1, 1).Select , this does nothing apparent for me. There is also the screenupdating, no effect again. For reference this is an i5-9500 cpu with 16gb ram.
I have two leads I don't know yet how to implement
First is using "MS project tasks" which I do not yet understand how to use. And my worry is about putting that in a spreadsheet and it not working on my random colleage's computers ? Slow VBA macro writing in cells
The other is using the transpose but I can't find a good example AND it seems to be only for unidimensionnal arrays
I also found this suggestion but I'm not sure if that's a good fit for my case or if it would be any faster VBA Excel large data manipulation taking forever