Userform data

BuffaloGuy

New Member
Joined
Dec 5, 2017
Messages
43
Office Version
  1. 365
Platform
  1. Windows
I have a userform, and I am trying to get the data that is typed in the text boxes into certain cells on a new sheet in the same workbook.

On Sheet Intro, I click the new entry button and I get a userform titled NewForm. The text box renamed NameBox, gets a users name entered into it. You then click the OK button called OK_Button.

At which point I want the name typed into NameBox to be entered onto worksheet titled “Users” in cell L28.

I then want the Userform to close and have the form be cleared for the next time the “New Entry” button.

I have some code written tested out on my computer, but I’m typing this on phone.
 
Why are you working on a computer but typing your post on a phone? If you have code, it would be helpful to see what you have so we don't duplicate your work.

Here is the code that does exactly what you describe. But it's so simple I'm not sure this is what you really mean:
VBA Code:
Private Sub OK_Button_Click()
   If Me.NameBox.Value = "" Then
      MsgBox "You must enter a name"
   Else
      Worksheets("Users").Range("L28") = Me.NameBox.Value
      Unload Me
   End If
End Sub
 
Upvote 0
To answer your question ... the following code should be pasted in the UserForm code window :

VBA Code:
Option Explicit

Private Sub btnOK_Click()
    Dim ws As Worksheet
    Set ws = Sheets("Users")
   
    ws.Range("L28").Value = Me.NameBox.Value
   
End Sub
 
Upvote 0
A better approach might be :

Code:
Option Explicit
Private Sub btnCancel_Click()
    Unload Me
End Sub

Private Sub btnOK_Click()
    Dim ws As Worksheet
    Set ws = ActiveSheet
    Dim newRow As Long
    
    newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
    
    'The next two lines can be expanded as many times as needed for all the entry fields in your project
    
    ws.Cells(newRow, 1).Value = Me.txtFirstName.Value
    ws.Cells(newRow, 2).Value = Me.txtSurname.Value
    
End Sub
Sub CommandButton1_Click()
    Selection.EntireRow.Delete
End Sub

Download example workbook : Internxt Drive – Private & Secure Cloud Storage
 
Upvote 0

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