2014-02-13 3 views
0

코드 맨 아래 부분에 오류가 올 것입니다. 1 년 후에 (예 : 2010, 2011.2012) 각 워크 시트의 이름을 지정했습니다. 런타임 오류 13가 나타납니다. 특정 워크 시트에 데이터를 보내는 중 잘못 처리하고 있음을 알고 있습니다. 어떤 도움이 크게 appriciated 것입니다. 년도() 입력으로 날짜을 필요로하기 때문에런타임 오류 13 VBA Excel 2007

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 
+0

이 - 각각의 현재 년도 의 이름을 반환됩니다 SH 있음 ThisWorkbook.Worksheets SH.Name = 연도 (연도) 인 경우 WrkSheet = SH를 설정하십시오 Exit 끝내기 –

답변

2
Year(Year(Now())) 

이 실패합니다!

당신은 아마 필요 : 다음

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 
+0

감사합니다! 다른 문제를 도와 주시겠습니까? 새로운 요구 사항은 콤보 박스를 여러 선택을 허용하고 단일 셀에 입력 할 수있는 목록 상자로 대체하는 것이 었습니다. 내가 말하고있는 것은 Me.Reason_RRT_Called입니다. 도움이 될 것입니다. –

+0

죄송합니다 ............... UserForms은 내 힘이 아닙니다 ......... 아무도 응답하지 않으면 새 게시물을 엽니 다. –

관련 문제