Created
January 21, 2016 04:31
-
-
Save danwagnerco/526f9f57f385486ea305 to your computer and use it in GitHub Desktop.
This macro converts successful VLOOKUP formulas into values (thereby "locking" them) in case your lookup table has to change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Public Sub ConvertLookupsToValues() | |
Dim lngLastRow As Long, lngIdx As Long | |
Dim varLookups As Variant | |
'Everything happens on the Ledger sheet | |
With ThisWorkbook.Worksheets("Ledger") | |
'Identify the last-occupied row in column D on the Ledger sheet, | |
'then store all the values in a column array (variant type) | |
lngLastRow = .Cells(.Rows.Count, 4).End(xlUp).Row | |
varLookups = .Range(.Cells(3, 4), .Cells(lngLastRow, 4)) | |
'Loop through the array, writing values over the existing | |
'formulas if the lookup was successful | |
For lngIdx = 1 To UBound(varLookups) | |
If varLookups(lngIdx, 1) <> 0 Then | |
.Cells(2 + lngIdx, 4) = varLookups(lngIdx, 1) | |
End If | |
Next lngIdx | |
End With | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment