运行时错误13 VBA Excel 2007

加里·卡罗尔

错误底部将在代码的年部分中出现。我在一年后即2010年,2011.2012年为每个工作表命名。我遇到了运行时错误13。我知道将数据发送到特定工作表时做错了什么。任何帮助将不胜感激。

Option Explicit
Dim WrkSheet As Worksheet

Private Sub CommandButton1_Click()
    Application.EnableEvents = False

    Dim ssheet As Workbook
    Dim cellVal1 As String, cellVal2 As String, cellVal3 As String, cellVal4 As String, cellVal5 As String, cellVal6 As String, cellVal7 As String, cellVal8 As String, cellVal9 As String, cellVal10 As String, cellVal11 As String, cellVal12 As String
    Dim cellVal13 As String, cellVal14 As String

    Dim shtCmb As String
    Dim RwLast As Long

    shtCmb = Me.Year.Value
    If shtCmb = "" Then
        MsgBox "Please choose a Year.", vbOKOnly
        Me.Year.SetFocus
    End If

    cellVal1 = Me.Year.Text
    cellVal2 = Me.Reason_RRT_Called.Text
    cellVal3 = Me.Me.Type_Of_Recomendations.Text
    cellVal4 = Me.Documentation_On_Templates.Text
    cellVal5 = Me.MD_Notified.Text
    cellVal6 = Me.Location.Text
    cellVal7 = Me.Code_Rapid_Response.Text
    cellVal8 = Me.Report_Sent_To_QM.Text
    cellVal9 = Me.Vital_Signs_Documneted.Text
    cellVal10 = Me.Assessments_Completed.Text
    cellVal11 = Me.Response_Time.Text
    cellVal12 = Me.Date_Of_Incedent.Text
    cellVal13 = Me.Patients_Name.Text
    cellVal14 = Me.Unit_Location.Text

    RwLast = Worksheets(shtCmb).Range("B" & Worksheets(shtCmb).Rows.Count).End(xlUp).Row

    Worksheets(shtCmb).Range("B" & RwLast + 1).Value = cellVal1
    Worksheets(shtCmb).Range("H" & RwLast + 1).Value = cellVal2
    Worksheets(shtCmb).Range("K" & RwLast + 1).Value = cellVal3
    Worksheets(shtCmb).Range("L" & RwLast + 1).Value = cellVal4
    Worksheets(shtCmb).Range("N" & RwLast + 1).Value = cellVal5
    Worksheets(shtCmb).Range("E" & RwLast + 1).Value = cellVal6
    Worksheets(shtCmb).Range("D" & RwLast + 1).Value = cellVal7
    Worksheets(shtCmb).Range("G" & RwLast + 1).Value = cellVal8
    Worksheets(shtCmb).Range("I" & RwLast + 1).Value = cellVal9
    Worksheets(shtCmb).Range("J" & RwLast + 1).Value = cellVal10
    Worksheets(shtCmb).Range("M" & RwLast + 1).Value = cellVal11
    Worksheets(shtCmb).Range("A" & RwLast + 1).Value = cellVal12
    Worksheets(shtCmb).Range("C" & RwLast + 1).Value = cellVal13
    Worksheets(shtCmb).Range("F" & RwLast + 1).Value = cellVal14

    Application.EnableEvents = True

End Sub

Private Sub optionCancel_Click()
    Unload Me
End Sub

Private Sub UserForm_Initialize()
    Dim SH As Worksheet
    Dim Entry As Variant

    'Auto date fill text box
    'Date_Of_Incedent.Value = Format(Date, "mm/dd/yyyy")

    'Year(Year(Now)) - Will return the name of the current Year
    For Each SH In ThisWorkbook.Worksheets
        If SH.Name = Year(Year(Now)) Then
            Set WrkSheet = SH
            Exit For
        End If
    Next

    'fill the combo box
    With Me.Year
        For Each Entry In [List1]
            .AddItem Entry
        Next Entry
        .Value = Year(Year(Now))
    End With

    'fill the combo box
    With Me.Reason_RRT_Called
        For Each Entry In [List2]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.Type_Of_Recomendations
        For Each Entry In [List3]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.Documentation_On_Templates
        For Each Entry In [List4]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.MD_Notified
        For Each Entry In [List5]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.Location
        For Each Entry In [List6]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.Code_Rapid_Response
        For Each Entry In [List7]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.Report_Sent_To_QM
        For Each Entry In [List8]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.Vital_Signs_Documneted
        For Each Entry In [List9]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.Assessments_Completed
        For Each Entry In [List10]
            .AddItem Entry
        Next Entry
    End With

    'fill the combo box
    With Me.Response_Time
        For Each Entry In [List11]
            .AddItem Entry
        Next Entry
    End With

End Sub
加里的学生
Year(Year(Now()))

将会失败,因为Year()需要输入日期作为日期

您可能需要:

Dim s As String
s = CStr(Year(Now))

接着:

For Each SH In ThisWorkbook.Worksheets
    If SH.Name = s Then
        Set WrkSheet = SH
        Exit For
    End If
Next

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

运行时错误13 VBA Excel

Excel VBA运行时错误类型不匹配13

Excel VBA运行时错误“ 13”:类型不匹配

Excel VBA If语句多条件运行时错误13

运行时错误 13' 类型不匹配 VBA excel

Excel VBA运行时错误1004

VBA Excel中的“运行时错误13:类型不匹配”错误

Application.Wait和Excel VBA运行时错误'13'类型不匹配

Excel运行时错误13中的VBA:类型不匹配

Excel VBA数据透视缓存类型不匹配运行时错误'13'

带有 Select Case 的 Excel VBA 运行时错误 13

运行时错误'13:比较日期时键入不匹配-EXCEL VBA

VBA Excel 错误运行时错误“53”

尝试检测是否关闭了用户窗体时在Excel VBA中得到“运行时错误'13':类型不匹配”

Excel VBA运行时错误“ 13”:将变量数组传递给Application.Index方法时,类型不匹配

VBA Excel:将范围内容放入数组时出现运行时错误 13 - 长单元格内容

我在VBA excel中编写编码器。我不断收到运行时错误13。它说不匹配

Excel VBA:.find函数返回运行时错误91

Excel VBA运行时错误91无法解决

Excel VBA 运行时错误 1004 - ThisWorkbook.Connections

Excel VBA-运行时错误1004

Excel VBA,Http.ResponseText运行时错误91

Excel VBA SUMIF运行时错误“ 424”:必需对象

Excel VBA:运行时错误424,需要对象

SQL Excel VBA运行时错误3709无效的连接

运行时错误6在Excel中的VBA中溢出

Excel VBA宏出现运行时错误'1004'

Excel VBA代码段导致运行时错误“ 438”

嵌套的For循环Excel VBA返回运行时错误9