saving and entering data in next sheet using command button

Souharda

New Member
Joined
Aug 24, 2014
Messages
1
On sheet 1 i have a command button and two text boxes, once an user fills the text boxes and click on the command button, the table on sheet1 will be saved and on sheet 2 the contents of the text box will be entered in the A and B columns and in C the time of the transaction will be entered. Can any one help me out with the code plz.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi Souharda,

I don't understand what you are asking for here?
the table on sheet1 will be saved

As for the textboxes, it depends on whether you're using Shape textboxes or ActiveX textboxes?

If using shape textboxes use this code;

Code:
Private Sub CommandButton1_Click()

Dim LastRw As Long

LastRw = Sheets("Sheet2").UsedRange.Rows.Count

Sheets("Sheet2").Cells(LastRw + 1, "A").Value = Sheets("Sheet1").TextBoxes("TextBox 1").Text
Sheets("Sheet2").Cells(LastRw + 1, "B").Value = Sheets("Sheet1").TextBoxes("TextBox 2").Text
Sheets("Sheet2").Cells(LastRw + 1, "C").Value = TimeValue(Now)

End Sub
If using ActiveX textboxes use this code;

Code:
Private Sub CommandButton1_Click()

Dim LastRw As Long

LastRw = Sheets("Sheet2").UsedRange.Rows.Count

Sheets("Sheet2").Cells(LastRw + 1, "A").Value = Sheets("Sheet1").TextBox1.Text
Sheets("Sheet2").Cells(LastRw + 1, "B").Value = Sheets("Sheet1").TextBox2.Text
Sheets("Sheet2").Cells(LastRw + 1, "C").Value = TimeValue(Now)

End Sub

Hope this helps,
Cheers,
Alan.
 
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,329
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top