对象“ _Global”的方法“工作表”失败-请帮助我

时间:2018-10-25 09:44:26

标签: vba

运行应用程序时,我遇到Error 1004 "Method 'Worksheets' of object'_Global' failed"的问题。

根据我所阅读的内容,我认为下面的代码存在不合格的参考问题。我认为我需要做的是具体参考该工作簿,但是我尝试了多种方法来完成此工作,但都失败了。有人可以协助吗?

    Private Sub CommandButton1_Click()
    Dim irow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("schooldetails")
    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) = TextBox2.Value
    .Range("D" & irow) = TextBox3.Value
    .Range("E" & irow) = ComboBox1.Value
    .Range("F" & irow) = TextBox4.Value
    .Range("G" & irow) = TextBox6.Value
    .Range("H" & irow) = TextBox7.Value
    .Range("I" & irow) = TextBox8.Value
    .Range("J" & irow) = TextBox9.Value
    .Range("K" & irow) = TextBox10.Value
    .Range("L" & irow) = TextBox11.Value
    End With
    clear
    Frame1.Enabled = True
    Frame2.Enabled = True
    End Sub


    Private Sub schooldetails()
    Dim SchlCd, SchlPin As Integer
    Dim SchlName, SchlAdd, SchlDist As String
    Dim irow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("schooldetails")
    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) = TextBox2.Value
    .Range("D" & irow) = TextBox3.Value
    .Range("E" & irow) = ComboBox1.Value
    .Range("F" & irow) = TextBox4.Value
    End With
    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

0 个答案:

没有答案