The following Vlookup in my VBA code appears not to evaluate and I do not understand why:
varResourceId = Application.WorksheetFunction.VLookup(strResourceName, ResourceTbl, 2, 0)
Worth Noting:
1. If I enter the formula [=VLookup(RC3, ResourceTbl, 2, False)] into a cell, the cell is populated with valid results.
2. The vba vlookup code is in a different module than the sheet where the ResourceTbl data resides.
==================================================
Here is an excerpt of the VBA code where strResourceName is valid and populated. The ResourceTbl is built and populated with data.
Dim varResourceId As Variant
Dim strResourceName As String
strResourceName = Cells(Target.Row, intResourceColumn)
varResourceId = Application.WorksheetFunction.VLookup(strResourceName, ResourceTbl, 2, 0)
==================================================
Here is the macro module that builds ResourceTbl
Sub CreateResourceTable()
' CreateResourceTable Macro
'
ActiveWorkbook.Worksheets("AMR Data").Range("D2:E65000").Copy Destination:=Sheets("AMRIdTable").Range("A1")
With ActiveWorkbook.Worksheets("AMRIdTable")
.Columns("B:B").Cut
.Range("A1").Insert shift:=xlToRight
.ListObjects.Add(xlSrcRange, Range("A:B"), , xlYes).Name = "ResourceTbl"
.Range("A:B").RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
With .ListObjects("ResourceTbl").Sort
.SortFields.Clear
.SortFields.Add Key:=Range("A:A"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortTextAsNumbers
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
End Sub
======================================================
I am new to vba and excel, I'd appreciate any and all feedback
Kind Regards,
Kieran Shaw
varResourceId = Application.WorksheetFunction.VLookup(strResourceName, ResourceTbl, 2, 0)
Worth Noting:
1. If I enter the formula [=VLookup(RC3, ResourceTbl, 2, False)] into a cell, the cell is populated with valid results.
2. The vba vlookup code is in a different module than the sheet where the ResourceTbl data resides.
==================================================
Here is an excerpt of the VBA code where strResourceName is valid and populated. The ResourceTbl is built and populated with data.
Dim varResourceId As Variant
Dim strResourceName As String
strResourceName = Cells(Target.Row, intResourceColumn)
varResourceId = Application.WorksheetFunction.VLookup(strResourceName, ResourceTbl, 2, 0)
==================================================
Here is the macro module that builds ResourceTbl
Sub CreateResourceTable()
' CreateResourceTable Macro
'
ActiveWorkbook.Worksheets("AMR Data").Range("D2:E65000").Copy Destination:=Sheets("AMRIdTable").Range("A1")
With ActiveWorkbook.Worksheets("AMRIdTable")
.Columns("B:B").Cut
.Range("A1").Insert shift:=xlToRight
.ListObjects.Add(xlSrcRange, Range("A:B"), , xlYes).Name = "ResourceTbl"
.Range("A:B").RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
With .ListObjects("ResourceTbl").Sort
.SortFields.Clear
.SortFields.Add Key:=Range("A:A"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortTextAsNumbers
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
End Sub
======================================================
I am new to vba and excel, I'd appreciate any and all feedback
Kind Regards,
Kieran Shaw
Last edited: