Rakeshdimpal
Board Regular
- Joined
- Nov 2, 2015
- Messages
- 65
I need a VBA Code for entering data into a table having 4 column namely Name, Date, Amount and Mobile number.
I'm assuming you would have text boxes on this userform (NameTextBox, DateTextBox, AmountTextBox, MobileNumberTextBox, etc.. whatever you name them)
So when you click your button on the userform to add the data, you have to find the next empty row, paste the data from the userform into the table, and then clear the userform:
'This is your userform code for the button you click to paste the data to the table
Private Sub UserformButton_Click()
Call Module2.DataEntry
With UserformName
.NameTextBox.Text = ""
.DateTextBox.Text = ""
.AmountTextBox.Text = ""
.MobileNumberTextBox.Text = ""
End With
End Sub
'This Sub is in your module
Sub DataEntry()
Dim n As Integer: n = 2
Do Until IsEmpty(Worksheets("Sheet1").Cells(n, 1))
n = n + 1
Loop
With Worksheets("Sheet1")
.Cells(n, 1) = UserformName.NameTextBox.Text
.Cells(n, 2) = UserformName.DateTextBox.Text
.Cells(n, 3) = UserformName.AmountTextBox.Text
.Cells(n, 4) = UserformName.MobileNumberTextBox.Text
End With
End Sub