在下面的代碼中,我在cRange. 每個空單元格都應該填充一個基于 VLOOKUP 的值。我正在查找的值是rngLookup緊靠左側的字串的前五個字符cRange.Cells(x)。
對于使用 VLOOKUP 公式的行,宏會引發“引數數量錯誤或屬性分配無效”錯誤。我無法弄清楚我的語法有什么問題。請幫忙。
Dim rngLookup As Range
Set rngLookup = Sheets("Account Descriptions").Range("A2:B468")
LastRow = Sheets("Summary").Range("B6").End(xlDown).Row
Set cRange = Sheets("Summary").Range("F6:F" & LastRow)
For x = cRange.Cells.Count To 1 Step -1
With cRange.Cells(x)
If IsEmpty(.Value) Then
.Formula = Application.vLookup(rngLookup, .Left(ActiveCell.Offset(0, -1), 5), 2, False)
End If
End With
Next x
uj5u.com熱心網友回復:
- 您的引數順序已關閉:首先查找值,其次查找范圍。
.Left是范圍的屬性;你想要這個Left功能。- 您正在撰寫一個值,而不是公式,所以使用
.Value. - 不要使用
ActiveCell.
.Value = Application.Vlookup(Left(.Offset(,-1).Value, 5), rngLookup, 2, False)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/519603.html
標籤:擅长vba
上一篇:加快VBA中的按鈕格式化
下一篇:VBAExcel的正則運算式模式
