VBA to send data from input box to another worksheet

adityatandel

Board Regular
Joined
Aug 10, 2007
Messages
71
I have created a form for my work. And I have input boxes for users to add data that I would like to get stored in another worksheet. What is the vba code to send data for an input box to another worksheet at the bottommost empty row; first column.

Private Sub cmdAddData_Click()

' Collect user name, find the space between first and last names, and separate the names.
UserName = InputBox("Enter the Program Name.", "Program Name")
spaceLoc = InStr(1, UserName, " ")
firstName = Left(UserName, spaceLoc - 1)

Thank you,
Adi
 
The above was tested, and combines your Subs!
This other code below, should add the additional steps to work with the name parts as well:

Sub cmdAddData_Click()
Dim strUserName$, strFirstName$, strLastName$
Dim lngLstRow&, strLength&, lngSpaceLoc&
Dim sw1 As Boolean

'Get program name from user!
strUserName = InputBox("Enter the Program Name.", "Add Program Name!")

'Find First and last names.
On Error GoTo myErr

strLength = Len(strUserName)
lngSpaceLoc = InStr(1, strUserName, " ")
strFirstName = Left(strUserName, lngSpaceLoc - 1)
strLastName = Right(strUserName, strLength - lngSpaceLoc)
sw1 = True

'Optional, if good User Name, show data.
MsgBox "Total Length: " & strLength & vbLf & _
"1st Space: " & lngSpaceLoc & vbLf & _
"First: " & strFirstName & vbLf & _
"Last: " & strLastName, _
vbInformation + vbOKOnly, _
"User InPut Results"

myErr:
' Message box for user if program name already exists in the database
If UCase(strUserName) = "WARRANTY" Then
MsgBox "Program Name already exists in the database", _
vbCritical + vbOKOnly, _
"Error!"

Else

' Data from input boxes added to the database"
With Sheets("Data")
lngLstRow = .UsedRange.Rows.Count + .UsedRange.Row
.Range("A" & lngLstRow).Value = strUserName
End With

MsgBox "Program Name successfully added to the database!", _
vbExclamation + vbOKOnly, _
"Added!"

End If

Sheets("Front End").Select

'Test for good user name.
If sw1 = False Then
GoTo
myStrMsg
Else

GoTo
myEnd
End If

myStrMsg:
'User Name Warrning!
MsgBox """" & strUserName & """ is not a proper Name!", _
vbCritical + vbOKOnly, _
"InPut Warrning!"

myEnd:
End Sub

Hi Joe,
This code is excellent and may also work on the question I have, I just may need some help to modify it a bit. I created a form and need data to go to my worksheet named Tracker but to put the information input on the form to a specific row with the unique PO number in column A. I have attached my form and tracker to show you what I mean. If you could help me out as well I would appreciate it!
 

Attachments

  • Form snip.PNG
    Form snip.PNG
    81.6 KB · Views: 9
  • tracker.PNG
    tracker.PNG
    94.3 KB · Views: 9
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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