我在使用下面的 vba 脚本时遇到了一些问题。这很简单。它旨在获取下拉列表的值并根据另一张表中的是/否/空值进行响应。代码工作正常,除了 vlookup 行中存在阻止脚本运行的问题。
前两行 vlookup 行返回“应用程序定义或对象定义错误”,第三行返回“数据类型不匹配”错误。公式引用的每个单元格都被格式化为文本,所以我不确定问题是什么......任何反馈都会非常有帮助。谢谢!
If Not Intersect(Target, Range("countryProductCell")) Is Nothing Then
lastcolumn = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count
cellRow = Target.Row
defaultCellColumn = 4
Dim countryIndex As Variant
countryIndex = Array(6, 6, 30, 21, 35, 29, 32, 20, 23, 18, 19, 34, 33, 22, 31, 26, 25, 27, 28, 7, 8, 15, 12, 10, 13, 11, 16, 17, 9)
i = 0
For Each countryCell In Range(Cells(cellRow, 5), Cells(cellRow, lastcolumn))
'If Default is selected
'If Not Target.Value = "(Select Title)" Then
'If Product is not selected
If countryCell.Value = "Use Default" Then
'Look Up Purchaseablility, Needs Array
If Not Application.VLookup(ActiveSheet.Cells(cellRow, defaultCellColumn), Sheets("Active Product Catalog").Range("E:AK"), countryIndex(i), False) = "Yes" Then
'If Not Purchaseable, Change Color
countryCell.Interior.ColorIndex = 3
End If
If Application.VLookup(ActiveSheet.Cells(cellRow, defaultCellColumn), Sheets("Active Product Catalog").Range("E:AK"), countryIndex(i), False) = "Yes" Then
'If Purchaseable, Change Color
countryCell.Interior.ColorIndex = 35
End If
Else
If Application.VLookup(ActiveSheet.Cells(cellRow, countryCell.Column), Sheets("Active Product Catalog").Range("E:AK"), countryIndex(i), False) = "Yes" Then
countryCell.Interior.ColorIndex = 35
End If
End If
'Else
'End If
i = i + 1
Next
End If