A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
First thing: when you declare varibales and objects, you have to specify the type each time otherwise they are just declared as Variants. You should do:
Dim itemrng As Range, qtyrng As Range, toqtyrng As Range, unirng As Range, laborrng As Range
not:
Dim itemrng, qtyrng, toqtyrng, unirng, laborrng As Range
Not sure whether that would cause a noticable drop-off in speed though (but doing it correctly wil help you by providing the correct intellisense dropdowns each time you type a dot).
Secondly, to enter a formula in a cell you should use:
toqtyrng.Formula = "=" & qtyrng.Address & "*$G$4"
not:
toqtyrng.Value = ("=" & qtyrng.Address & "*$G$4")
Thirdly, I notice you're doing a VLOOKUP over 100,000 rows (x4 columns). Do you really need that many rows? Could you find the last row by doing something like:
Dim lastRow As Long
lastRow = Range("A" & Sheets(shname).Rows.Count).End(xlUp)
?
Final point. Best way to speed up the code is to suspend screen updating and calculations. top and tail your code with:
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'Do stuff... Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Please give that a try and post back if it's still really slow.
Hope that helps.
Cheers
Rich