• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

call Function in userform

delta

Member
i put code
Code:
Sub Add_Data()
Worksheets("Cash_Book_Print").Range("E4").Value = TextBox1.Value
Worksheets("Cash_Book_Print").Range("D5").Value = TextBox2.Value
Worksheets("Cash_Book_Print").Range("A5").Value = TextBox3.Value
Worksheets("Cash_Book_Print").Range("C5").Value = TextBox4.Value
Worksheets("Cash_Book_Print").Range("A7").Value = TextBox5.Value
Worksheets("Cash_Book_Print").Range("A9").Value = TextBox6.Value
Worksheets("Cash_Book_Print").Range("E12").Value = TextBox7.Value
End Sub
in module and call it from userform command button(call Add_Data) but show error what is wrong in code.
 
Last edited by a moderator:
write all the code in Private Sub CommandButton1_Click, it will work

Code:
Private Sub CommandButton1_Click()

Worksheets("Sheet1").Range("E4").Value = TextBox1.Value
Worksheets("Sheet1").Range("D5").Value = TextBox2.Value
Worksheets("Sheet1").Range("A5").Value = TextBox3.Value
Worksheets("Sheet1").Range("C5").Value = TextBox4.Value
Worksheets("Sheet1").Range("A7").Value = TextBox5.Value
Worksheets("Sheet1").Range("A9").Value = TextBox6.Value
Worksheets("Sheet1").Range("E12").Value = TextBox7.Value
   
End Sub
 
Hi ,

If your command button is named Add_Data , then your event procedure will be by default named Add_Data_Click.

Inside this procedure , you cannot have a line of code such as :

Call Add_Data

since the term Add_Data refers to the command button.

Either rename your command button to something like AddData or Add_Data1 , or rename your called procedure to AddData or Add_Data1.

If you rename your command button , Excel will automatically add a blank procedure named either AddData_Click or Add_Data1_Click.

Narayan
 
Put this code under your Add_Data button
(right click on the button -> programcode..)
Give the button the name AddData
Code:
Private Sub AddData_Click()
With Worksheets("Cash_Book_Print")
.[E4].Value = TextBox1.Value
.[D5].Value = TextBox2.Value
.[A5].Value = TextBox3.Value
.[C5].Value = TextBox4.Value
.[A7].Value = TextBox5.Value
.[A9].Value = TextBox6.Value
.[E12].Value = TextBox7.Value
End With
End Sub
 
Last edited:
Back
Top