2017-12-28 16 views
-1

2 가지 형식이 생성되었습니다. form1은 2 개의 텍스트 상자를 포함하고, form2는 2 개의 텍스트 상자와 1 개의 명령 단추를 포함합니다. 이 코드는 작동하지 않습니다. 올바른 것을 쓰는 방법?excel vba의 controls 명령에 오류가 있습니다

Private Sub CommandButton1_Click() 
Dim nom As String 
nom = UserForm2.TextBox2 
UserForm1.Controls("TextBox" & nom) = UserForm2.TextBox1 
End Sub 

UPDATE :

유치원 1 :

Private Sub textbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 
form2.show 
form2.textbox2=1 
End Sub 
Private Sub textbox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 
form2.show 
form2.textbox2=2 
End Sub 

형식 2 :

Private Sub commandbutton_click() 
unload me 
Dim nom As String 
    nom = UserForm2.TextBox2 
    UserForm1.Controls("TextBox" & nom) = UserForm2.TextBox1 
End Sub 
+0

코드는 나를 위해 작동합니다. 그래서 나는 그것이 이미 "올바른 것"이라는 것을 의미합니다. (최소한, 당신이 원하는 것을하고 있다고 생각하지 않는 이유에 대한 단서가 생길 때까지입니다.) – YowE3K

+0

내 완전 작성 업데이트 –

+0

죄송합니다, 귀하의 의견을 이해할 수 없습니다. 작동하지 않는 것의 유일한 설명은 "이 코드가 작동하지 않습니다"라는 질문에 이미 작성한 것입니다. – YowE3K

답변

0

당신이 달성하지만, 함께하려고 시도하고있는 무슨 확실하지 :

유치원 1 :

Private Sub textbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 
    form2.show 
    form2.textbox2.Value = "1" 
End Sub 

Private Sub textbox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 
    form2.show 
    form2.textbox2.Value = "2" 
End Sub 

형식 2 :

Private Sub commandbutton_click() 
    Dim nom As String 
    nom = me.TextBox2.Value 
    UserForm1.Controls("TextBox" & nom).Value = UserForm2.TextBox1.Value 
    unload me 
End Sub 
0

해결.

Form1에

Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 
Unload Me 
UserForm2.TextBox2 = 1 
UserForm2.Show 
End Sub 

Private Sub TextBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 
Unload Me 
UserForm2.TextBox2 = 2 
UserForm2.Show 
End Sub 


Private Sub UserForm_Initialize() 
TextBox1 = Cells(2, 2) 
TextBox2 = Cells(3, 2) 
End Sub 

형식 2는

Private Sub CommandButton1_Click() 
On Error Resume Next 
Dim nom As String 
nom = TextBox2 
UserForm1.Controls("textbox" & nom) = UserForm2.TextBox1 
Cells(nom + 1, 2) = UserForm2.TextBox1 
Unload Me 
UserForm1.Show 
End Sub