2014-01-20 2 views
0

나는 직접 작업을 시도하고 질문을 다시 편집했습니다. 그래서 나는 enter image description hereExcel VBA UserForms

모습의 사진을 업로드 한 내가 행

'Determine Empty Row 
emptyRow= WorksheetFunction.Counta(Range("A:A"))+1 
'Transfer into to cells 
Cells(emptyRow, 1).Value= NOD_Text.Value 
Cells(emptyRow,2).Value=TOD_Text.Value 
Cells(emptyRow,3).Value=Program_Text.value 
Cells(emptyRow,4).Value=email_Text.value 
Cells(emptyRow,5).Value=OPN_Text.value 
Cells(emptyRow,6).Value=CPN_Text.Value 

를 엑셀 텍스트 상자에서 정보를 전송하려면 다음 코드를 사용했습니다 (엑셀 VBA에서 사용자 정의 폼을했습니다 이해 관계자 (시트 A, 시트 B, 시트 C, 시트 D 등)와 동일한 시트가 여러 개 있고 확인란에 따라 위의 정보를 전송하려고합니다. 예를 들어, 확인란 A, B, C를 클릭하면 정보가 시트 A, B, C로 전송됩니다.

이해 관계자의 체크 박스에 따라 시트를 활성화하는 방법을 잘 모르겠습니다 ...

If A_Checkbox.Value=True then Worksheets(A).Activate then Cells(emptyRow, 1).Value= NOD_Text.Value 
Cells(emptyRow,2).Value=TOD_Text.Value 
Cells(emptyRow,3).Value=Program_Text.value 
Cells(emptyRow,4).Value=email_Text.value 
Cells(emptyRow,5).Value=OPN_Text.value 
Cells(emptyRow,6).Value=CPN_Text.Value 

위의 코드가 맞는지는 확실하지 않지만 문제는 ... 사람이 확인란 3 이해 관계자 (A, B, C) ... 인 경우 확실하지 않은 경우 ...? 나는 그 코드를 어떻게 작성 해야할지 모르겠다. ...

또한, 어떤 상자가 chekced 되더라도 마스터 탭에 모든 informatoin을 넣고 싶지만 항상 마스터 탭을 활성화하는 방법을 모른다. .

내가이

+2

* 도움이 필요 하시거나 참고 자료/링크/가이드 라인을 제안 해 주시면 매우 감사하겠습니다. *이 사이트가 작동하는 방식이 아닙니다. 나는'UserForm' (Google it)을 사용하도록 제안 할 것이다. 그렇지 않으면 일련의'Inputbox'가 트릭을 할 것이다. 그러나 전체 응용 프로그램을 코딩하는 데 광범위한 질문을하는 것처럼 보입니다. 여기서는 범위를 벗어납니다. 행운을 빕니다. –

+0

질문을 다시 수정했습니다.이 내용이 명확하면 알려주세요. – Doolie1106

답변

0

내가 컨트롤의 태그 속성을 사용하는 것이 작업을 수행하기 전에보다 더 명확 바랍니다.

각 텍스트 상자의 TAG 속성에서 값을 붙여 넣을 셀 참조를 작성합니다 (예 : $ B $ 2).

각 확인란의 TAG 속성에서 해당 컨트롤에 연결된 시트 이름을 작성합니다 (예 : Sheet1).

Private Sub CommandButton1_Click() 
    Dim ctrl As Control 
    Dim ctrl1 As Control 

    'Cycle through each control looking for checkboxes. 
    For Each ctrl In Me.Controls 

     If TypeName(ctrl) = "CheckBox" Then 

      'If the checkbox is ticked 
      If ctrl.Value = True Then 

       With ThisWorkbook.Worksheets(ctrl.Tag) 'Grab the sheet name from the check box. 

        'Cycle through each control looking for textboxes. 
        For Each ctrl1 In Me.Controls 
         If TypeName(ctrl1) = "TextBox" Then 
          .Range(ctrl1.Tag) = ctrl1.Value 'Grab the cell address from the text box. 
         End If 
        Next ctrl1 
       End With 
      End If 
     End If 
    Next ctrl 
End Sub 
0

당신이 경우에 시트를 활성화 필요하고 firt 빈 셀을 알고 후 :

If A_Checkbox.Value=True then 
    Worksheets("A").Activate 
ElseIf B_Checkbox.Value=True then 
    Worksheets("B").Activate 
End If 

emptyRow=Activesheet.range("A1000000").end(XlUp).Row+1 
Cells(emptyRow,2).Value=TOD_Text.Value 
0

을이 해야하는

다음 명령 단추 뒤에이 같은 코드 뭔가를 써서 트릭을 수행하십시오 :

Private Sub AddButton_Click() 

Dim CB As Control 

For Each CB In UserForm1.Controls 

    If TypeName(CB) = "CheckBox" Then 

     If CB.Value = True Then 

      ShtNm = CB.Caption 

      With ActiveWorkbook.Sheets(ShtNm) 

       'Determine Empty Row 
       emptyRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row + 1 
       'Transfer into to cells 
       .Cells(emptyRow, 1).Value = NOD_Text.Value 
       .Cells(emptyRow, 2).Value = TOD_Text.Value 
       .Cells(emptyRow, 3).Value = Program_Text.Value 
       .Cells(emptyRow, 4).Value = email_Text.Value 
       .Cells(emptyRow, 5).Value = OPN_Text.Value 
       .Cells(emptyRow, 6).Value = CPN_Text.Value 

      End With 

     End If 

    End If 

Next CB 

With ActiveWorkbook.Sheets("Master") 

    'Determine Empty Row 
    emptyRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row + 1 
    'Transfer into to cells 
    .Cells(emptyRow, 1).Value = NOD_Text.Value 
    .Cells(emptyRow, 2).Value = TOD_Text.Value 
    .Cells(emptyRow, 3).Value = Program_Text.Value 
    .Cells(emptyRow, 4).Value = email_Text.Value 
    .Cells(emptyRow, 5).Value = OPN_Text.Value 
    .Cells(emptyRow, 6).Value = CPN_Text.Value 

End With 

End Sub