【发布时间】:2018-11-19 12:18:18
【问题描述】:
我正在使用 Excel 创建一个工具,可以帮助我 DM 一个 D&D 活动,并且目前正在研究一个施法系统。我的目标是能够单击一个工作表(“战斗”)上的按钮,这将减少另一个工作表中的拼写槽(数值)(目标工作表的名称源自“战斗”中的文本值工作表),对应于给定的法术等级。这些值由“战斗”表中的单元格引用,这些值将随另一表中单元格的值而变化。 我的代码是:
Private Sub CastSpell_Click()
SpellAction "CastSpell"
End Sub
Sub SpellAction(ByVal action As String)
Dim Combat As Worksheet
Set Combat = ThisWorkbook.Sheets("Combat")
Dim Player As Worksheet
Set Player = ThisWorkbook.Sheets(Cells(5, 12).Text)
Dim foundCell As Range
Set foundCell = Player.Range("Z31", "Z39").Find(Left(Combat.Cells(18, 12).Text, 3))
If Not (foundCell Is Nothing) Then
r = foundCell.Row
Else
MsgBox "Couldn't find the current selection."
Exit Sub
End If
Select Case LCase(action)
Case "CastSpell"
If Not (Player.Cells(r, 28) = 0) Then
Cells(r, 28) = Cells(r, 28) - 1
Else
MsgBox "No remaining spell slots of this level."
Exit Sub
End If
End Select
End Sub
在哪里
Cells(5, 12) 表示从下拉列表中选择的文本字符串,Range("Z31", "Z39") 表示包含值 (1) 到 (9) 的列,Cells(18, 12) 表示法术名称,(例如:(1) Cure Wounds ),Cells(r, 28) 中引用的数字 28 指的是 AB 列,这是我希望减少其值的单元格的列。
目前,当我单击按钮(名为“CastSpell”并位于“战斗”表中)时,它会运行SpellAction 代码,找到Player、foundCell 和@987654329 的正确值@ 没有错误消息,但不执行 "CastSpell" 内的代码。我哪里错了?
【问题讨论】: