Button to add data to different sheet

jepakc

New Member
Joined
Apr 3, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello! I'm very new to VBA and stuff like this. I have sheet named "component list" and second sheet named "finished product". I have button on "component list" sheet and i hope anytime i push the button it would generate serial number to the "finished product" sheet on column A and add current date to column B. I have headings in A1 and B1. The serial number can be as basic as "001, 002, 003 ...". I have been trying different things but i'm stuck with this so any help will be much appreciated!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This script will ask for the serial number you want since you did not explain how to know what the serial number would be. And the script adds the data to a sheet named: "finished product"
Put this script in your button.
VBA Code:
Sub My_Script()
'Modified 4/3/2022  11:34:27 PM  EDT
Application.ScreenUpdating = False
Dim ans As String
ans = InputBox("Enter your serial number")
Dim Lastrow As Long
Lastrow = Sheets("finished product").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("finished product").Cells(Lastrow, 1).Value = ans
Sheets("finished product").Cells(Lastrow, 2).Value = Date
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
This script will ask for the serial number you want since you did not explain how to know what the serial number would be. And the script adds the data to a sheet named: "finished product"
Put this script in your button.
VBA Code:
Sub My_Script()
'Modified 4/3/2022  11:34:27 PM  EDT
Application.ScreenUpdating = False
Dim ans As String
ans = InputBox("Enter your serial number")
Dim Lastrow As Long
Lastrow = Sheets("finished product").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("finished product").Cells(Lastrow, 1).Value = ans
Sheets("finished product").Cells(Lastrow, 2).Value = Date
Application.ScreenUpdating = True
End Sub
Thank you very much, it works! I will try to modify the serial number specification part when i know the exact serial number format.
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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