Excel VBA applying formula problem

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

In a large data I am applying formula in a column through vba, and it is taking lot of time to fetch data, please help me how can I optimize this code, so the code can run fast.

Code:
For i = 2 To 480000
    'Cells(i, 10).Select
    Cells(i, 10).Formula = "=vlookup(A2,'2G_NSC RF Data'!A:F,2,0)"
    If IsError(Cells(i, 10).Value) Then
        Cells(i, 10).Formula = "=vlookup(A2,'A_BTS'!A:J,6,0)"
    End If
    If IsError(Cells(i, 10).Value) Then
        Cells(i, 10).Formula = "=vlookup(A2,'2G All Vendor Dump'!A:J,8,0)"
    End If
    If IsError(Cells(i, 10).Value) Then
        If Cells(i, 3) = "" Then
            Cells(i, 3) = "Either Source/Target Cell Data Not Found"
        End If
    End If
Next i

Thanks
Kashif
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Wrap your code in the following:

Code:
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual


Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

It appears your are populating an if statement and the checking to see if that result is an error. If so then you are populating a vlookup based on another sheet. and repeating this process through three different sheets.

I would suggest consolidating your data on a separate page and running one vlookup. Also it appears your for script is using almost a half million iterations and I wonder if you truly need that many. Can you add a variable that identifies how many iterations you will truly need?
 
Last edited:
Upvote 0
Hi Beyond_avarice,

Thanks for reply, I like your idea about consolidating all the sheets data into one sheet, and then apply one vlookup.

Thanks
Kashif
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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