【发布时间】:2017-11-21 02:11:34
【问题描述】:
此代码在单元格 A8 或 A17(取决于哪个切换处于活动状态)中引发 #VALUE 错误,而不是来自“dataWeaponField”命名范围的字符串值。 (例如)单元格 A17 中的这个 Excel 公式可以正常工作:=VLOOKUP(B17,dataWeaponField,2,FALSE)。我试图在 VBA 中简单地复制这个公式。
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Column = 1 And Target.Row = 7 Then 'CLICK TO SWAP WEAPONS
If Range("A8").Interior.ColorIndex = 6 Then 'Primary Weapon
Range("A8:C15").Interior.ColorIndex = 12 'Primary Weapon
Range("A17:C24").Interior.ColorIndex = 6 'Secondary Weapon
Range("A8").Value = "" 'Primary Weapon
Range("A17").Value = Application.VLookup(Range("B17"), ThisWorkbook.Names("dataWeaponField"), 2, False)
Else
Range("A8:C15").Interior.ColorIndex = 6 'Primary Weapon
Range("A17:C24").Interior.ColorIndex = 12 'Secondary Weapon
Range("A8").Value = Application.VLookup(Range("B8"), ThisWorkbook.Names("dataWeaponField"), 2, False)
Range("A17").Value = "" 'Secondary Weapon
End If
Range("A6").Select 'Cell above CLICK TO SWAP WEAPONS
End If
End Sub
【问题讨论】: