What is the most efficient way to fill a formula down/over and then replace with the value?

nayr1482

Board Regular
Joined
Feb 2, 2009
Messages
75
I am working on some code and part of the routine requires me to vlookup using the values on the left (dyanamic but this set ~45k rows) concantendated with the values along the top (dynamic but this set ~900 columns) and bring in the corresponding value from another sheet.

I have been trying to find an efficienct way to do this...but so far the best I found found is taking ~21 minutes.

First attempt was just entering the vlookup formula into the cell and then filling down and then filling across....this brought excel to its knees.
I then tried disabling screenupdating and calculations, then re-enabling calcs after the fill and doing range.value = range.value this ran but took a very long time
few more variations...

Where I am at now is ~21minutes to run:

VBA Code:
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    ws.Cells(7, 13).FormulaR1C1 = "=IFNA(VLOOKUP(RC2& "" | "" & R6C,'2.BOM_Explode'!C6:C7,2,FALSE)*RC3,"""")"
    ws.Cells(7, 13).AutoFill Destination:=Range(ws.Cells(7, 13), ws.Cells(7, c)), Type:=xlFillDefault
    Application.Calculation = xlCalculationManual
    Range(ws.Cells(7, 13), ws.Cells(7, c)).AutoFill Destination:=Range(ws.Cells(7, 13), ws.Cells(r, c)), Type:=xlFillDefault
    Application.Calculation = xlCalculationAutomatic
    With Range(ws.Cells(7, 13), ws.Cells(r, c))
        .Cells.Copy
        .Cells.PasteSpecial xlPasteValues
        .Cells(1, 13).Select
    End With
    Application.CutCopyMode = False




Is there a more efficienct way to do this?
Thanks for your help!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

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