运行应用程序时出现错误1004“对象'_Global'的方法'工作表'失败”的问题。
根据我所阅读的内容,我认为下面的代码存在不合格的参考问题。我认为我需要做的是具体参考该工作簿,但是我尝试了多种方法来完成此工作,但都失败了。有人可以协助吗?
Private Sub CommandButton3_Click()
Dim irow As Long
Dim ws As Worksheet
If CheckBox1.Value = True Then
cricket
End If
If CheckBox2.Value = True Then
Football
End If
If CheckBox3.Value = True Then
tennis
End If
If CheckBox4.Value = True Then
kabadi
End If
'MsgBox ("Data Not Saved")
End Sub
Public Sub cricket()
Set ws = Worksheets("cricket") ' The error is here
irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Range("A" & irow) = TextBox5.Value
.Range("B" & irow) = TextBox1.Value
.Range("C" & irow) = TextBox12.Value
.Range("D" & irow) = TextBox13.Value
.Range("E" & irow) = ComboBox2.Value
.Range("F" & irow) = "Cricket"
'MsgBox ("Data Saved")
'clear
End With
MsgBox ("Cricket Data Saved")
'clear
End Sub
Private Sub Football()
Set ws = Worksheets("Football")
irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Range("A" & irow) = TextBox5.Value
.Range("B" & irow) = TextBox1.Value
.Range("C" & irow) = TextBox12.Value
.Range("D" & irow) = TextBox13.Value
.Range("E" & irow) = ComboBox2.Value
.Range("F" & irow) = "Football"
'MsgBox ("Data Saved")
'clear
End With
MsgBox ("Football Data Saved")
'clear
End Sub
Private Sub kabadi()
Set ws = Worksheets("kabadi")
irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Range("A" & irow) = TextBox5.Value
.Range("B" & irow) = TextBox1.Value
.Range("C" & irow) = TextBox12.Value
.Range("D" & irow) = TextBox13.Value
.Range("E" & irow) = ComboBox2.Value
.Range("F" & irow) = "kabadi"
'MsgBox ("Data Saved")
'clear
End With
MsgBox ("kabadi Football Data Saved")
'clear
End Sub