当我使用 VLookup 运行倒数第三行时,我不断收到“对象 '_Global' 的方法 'Range' 失败”。这似乎是对失败的 Range("InfoOmArt") 的引用。我现在永远被困住了。
'Writes array "Artskoder" in a new worksheet
Dim InfoOmArt As Range
Sheets.Add
ActiveSheet.Name = "InformationOmArter"
Range("A1").Value = "Artsforkortelse"
Range("B1").Value = "Artskode"
Set InfoOmArt = ActiveSheet.Range("A1:B54")
InfoOmArt.Value = Artskoder
Worksheets("InformationOmArter").Move after:=Worksheets("Standarder")
Worksheets("Standarder").Activate
'Looping through sorter
Dim p As Range, abbr As Variant, MyStr As String
For Each p In Range(Cells(1, 1), Cells(44, 2))
abbr = Cells(p.Row, 1).Value
Debug.Print abbr
MyStr = Application.WorksheetFunction.VLookup(abbr, Range("InfoOmArt"), 2, False) 'Arg.1 as a string seems to only works if it searhes in the spreadsheat, not in an array
Cells(p.Row, 4).Value = MyStr
Next p