我是excel VBA的新手,我正在尝试编写代码,这些代码将接受两个NBA球队(一个主场和客场球队)的输入,测试以确保我的表中存在球队的名称,并输出名称如果找到了进入的团队以下是我的代码:
Private Sub CommandButton1_Click()
Dim homeTeam As Variant
Dim awayTeam As Variant
Dim h As Variant
Dim a As Variant
'declare variables
homeTeam = InputBox("Enter the Home team", "Home Team")
awayTeam = InputBox("Enter the Away team", "Away Team")
'Use input boxes to obtain both the home and away teams
Set h = ActiveSheet.Cells.Find(homeTeam)
Set a = ActiveSheet.Cells.Find(awayTeam)
With h.Range("A2:A31")
h = .Find(homeTeam)
If h Is Nothing Then
MsgBox ("Error: Home Team not found. Please Enter again")
End If
End With
Range("I1").Value = h
Range("J1").Value = h
End Sub
我遇到了这段代码的运行时错误91,我试图通过设置h和a的值来解决这个问题。 如前所述,我对这个编程很陌生,所以非常感谢任何输入。谢谢!!!