Submit Button - VBA Code

SoyuzGRU

New Member
Joined
Feb 17, 2022
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
I'm creating a User Form that will basically automate user input into an Excel Sheet for my organization. I have 3 Sheets on this Workbook labelled: Menu, Master and Data Validation. The Menu sheet allows users to select any forms available (connected through macros), the Master sheet saves all information that is input from sheets and Data Validation sheet is connected to some combo boxes available in the forms for easy updating.

Upon clicking submit on the User Form I always received error messages, even having tried multiple VBA codes and trying to make sense of these. Basically what I want is all the information from the User Form after clicking a submit button to be input into the Master sheet at the next available empty row. Any help is appreciated in advanced and below you will find my current code for my submit button:



Private Sub CommandButton1_Click()



Dim LR As Long 'LR = Last Row

Sheet1.Activate 'Activates the database sheet

LR = Sheet1.Cells(Rows.Count, 1).End(x1Up).Row

With Sheet1 'Each part of the form submitted into a separate column

.Range("A" & LR).Value = ComboBox1.Value
.Range("B" & LR).Value = ComboBox2.Value
.Range("C" & LR).Value = ComboBox3.Value
.Range("D" & LR).Value = TextBox1.Value
.Range("E" & LR).Value = TextBox2.Value
.Range("F" & LR).Value = TextBox3.Value
.Range("G" & LR).Value = TextBox4.Value
.Range("H" & LR).Value = ComboBox4.Value
.Range("I" & LR).Value = ComboBox5.Value
.Range("J" & LR).Value = TextBox5.Value
.Range("K" & LR).Value = ComboBox6.Value

End With 'Resets form to blank state after submitting

Me.ComboBox1.Value = Null
Me.ComboBox2.Value = Null
Me.ComboBox3.Value = Null
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.ComboBox4.Value = Null
Me.ComboBox5.Value = Null
Me.TextBox5.Value = ""
Me.ComboBox6.Value = Null

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Glad we could help and thanks for posting back (y)
 
Upvote 0
You need to replace the 1 with a letter L ....

EDIT:
so (x1Up) should have been (xlUp)
This is the single worst flaw in the VBA development environment. In the default font they use, the lowercase letter l and the numeral 1 are virtually indistinguishable.


L and one.JPG
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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