I currently have a VBA code where I do several lookups between a master sheet and multiple data-sheets, using the Application.Match function. If there's a match in the lookup in one of the sub-sheets, I paste the corresponding value to the master sheet. I do this for twelve columns in the master sheet (one for each month).
My code is running very slow and I suspect it's due to the fact that I'm not using arrays, and hence does a lot of printing into individual cells while running the code. I would like to speed up performance using arrays, but I can't really figure out how to convert my existing code, where I paste to ranges in a for loop, to printing to an array instead.
My code looks like this:
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
With aSheet
For i = FindEmptyRow To FindRow
mtchrw = 0
On Error Resume Next
mtchrw = Application.WorksheetFunction.Match(.Range("A" & i), Sheets("datasheet1").Range("A:A"), 0)
On Error GoTo 0
If mtchrw > 0 Then
Sheets("datasheet1").Range("B" & mtchrw & ":B" & mtchrw).Copy
.Range("B" & i & ":B" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("C" & mtchrw & ":C" & mtchrw).Copy
.Range("D" & i & ":D" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("D" & mtchrw & ":D" & mtchrw).Copy
.Range("F" & i & ":F" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("E" & mtchrw & ":E" & mtchrw).Copy
.Range("H" & i & ":H" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("F" & mtchrw & ":F" & mtchrw).Copy
.Range("J" & i & ":J" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("G" & mtchrw & ":G" & mtchrw).Copy
.Range("L" & i & ":L" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("H" & mtchrw & ":H" & mtchrw).Copy
.Range("N" & i & ":N" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("I" & mtchrw & ":I" & mtchrw).Copy
.Range("P" & i & ":P" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("J" & mtchrw & ":J" & mtchrw).Copy
.Range("R" & i & ":R" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("K" & mtchrw & ":K" & mtchrw).Copy
.Range("T" & i & ":T" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("L" & mtchrw & ":L" & mtchrw).Copy
.Range("V" & i & ":V" & i).PasteSpecial Paste:=xlPasteValues
Sheets("datasheet1").Range("M" & mtchrw & ":M" & mtchrw).Copy
.Range("X" & i & ":X" & i).PasteSpecial Paste:=xlPasteValues
End If
Next i
End With
In my datasheet, the columns are adjecent to each other, while in my master sheet, there's a column in between each. That's the reason I have split up the copy/paste function in twelve parts, if that makes sense.
How would I go about doing this task using an array, where I avoid doing the copy/paste-function in twelve parts?
I apologize for my english. It's not my first language.
Kind regards, Magnus
edit:
FindRow and FindEmptyRow reflects the first and last row in column A in the aSheet.
Snapshot of aSheet

The values from datasheet1 are multiplied by 37 before being pasted to master sheet.



.Range("B" & i).value=Sheets("datasheet1").Range("B" & mtchrw).valuewhich is more efficient.