这是我第一次发帖,所以如果我搞砸了任何论坛礼仪,请告诉我!
我有一个包含标签、两个组合框和按钮的用户表单。标签的文本设置在 sub 中,是描述游戏的文本。我要求用户从两个组合框中选择两位裁判该游戏的裁判。该按钮是“下一场比赛”按钮。当用户单击“下一场比赛”按钮时,我将两位裁判与“裁判”工作表上的名称列表进行匹配。然后我希望能够使用标签中的文本(说明它是哪个游戏)并将其粘贴到与裁判姓名相邻的第一个空行中。代码在“下一场比赛”按钮的“点击按钮”事件上。我目前收到运行时错误“1004”。
Private Sub nextGameBtn_Click()
Dim ump1 As String
Dim ump2 As String
Dim endRow As Long
Dim ump1Row As Range
Dim ump2Row As Range
Dim ump1EndColumn As Long
Dim ump2EndColumn As Long
Dim game As String
ump1 = selectUmpsForm.ComboBox1.Value
ump2 = selectUmpsForm.ComboBox2.Value
endRow = Worksheets("Umpires").Cells(Rows.Count, 1).End(xlUp).Row
Set ump1Row = Worksheets("Umpires").Range("A2:A" & endRow).Find(What:=ump1, LookIn:=xlValues, LookAt:=xlWhole)
ump1EndColumn = Worksheets("Umpires").Range("IV" & ump1Row.Row).End(xlToLeft).Column + 1
Set ump2Row = Worksheets("Umpires").Range("A2:A" & endRow).Find(What:=ump2, LookIn:=xlValues, LookAt:=xlWhole)
ump2EndColumn = Worksheets("Umpires").Range("IV" & ump2Row.Row).End(xlToLeft).Column + 1
game = selectUmpsForm.lblGame.Caption
Worksheets("Umpires").Range(Cells(ump1Row.Row, ump1EndColumn), Cells(ump2Row.Row, ump2EndColumn)).Value = game
gameCount = gameCount + 1
Call displayBox(gameCount)
End Sub
运行时错误发生在该行:
Worksheets("Umpires").Range(Cells(ump1Row.Row, ump1EndColumn), Cells(ump2Row.Row, ump2EndColumn)).Value = game
如果有一个离开我可以阅读标签文本而不必返回创建它的源?这是我的运行时错误的原因吗?
任何建议将不胜感激。干杯我