multiple save commands

jwbatey07

New Member
Joined
Apr 14, 2020
Messages
33
Office Version
  1. 365
Platform
  1. Windows
I have two userforms. the first one works good. it was constructed with one UOM and length in mind for assemblies. I realized the need to make it flexible so I created another userform looking at QTY's on userform1 and giving the user the ability to add other UOM and lengths. i'm trying to get the data entered in the second userform to come over with the data from userform1 into the "DATA" spreadsheet.

code below. information from userform1 is getting put into the "DATA" sheet but the data from the comboboxes and textboxes on Userform2 are not coming over. is this possible? any help would be great.

1590185100198.png


USERFORM1 SAVE COMMAND
Dim iRow As Long
iRow = Sheets("Data").Range("A1048576").End(xlUp).row + 1

With ThisWorkbook.Sheets("DATA")

.Range("A" & iRow).value = iRow - 1
.Range("B" & iRow).value = ComboBox4.Text
.Range("C" & iRow).value = ComboBox20.Text 'UOM'
.Range("D" & iRow).value = TextBox2.Text 'Lenght'
.Range("E" & iRow).value = ComboBox6.Text
.Range("F" & iRow).value = ComboBox8.Text
.Range("G" & iRow).value = ComboBox11.Text
.Range("H" & iRow).value = ComboBox12.Text
.Range("i" & iRow).value = ComboBox19.Text
.Range("j" & iRow).value = ": " & Environ("USERNAME")

End With

USERFORM2 SAVE COMMAND
Private Sub cmbsave2_Click()

Dim iRow As Long
iRow = Sheets("Data").Range("A1048576").End(xlUp).row + 1

With ThisWorkbook.Sheets("DATA")

.Range("A" & iRow).value = iRow - 1
.Range("B" & iRow).value = UserForm1.ComboBox4.Text

Dim x As Long
For x = 31 To 50
If Me.Controls("COMBOBOX" & x).Text <> 0 And Me.Controls("TEXTBOX" & x) <> 0 Then 'only pull information that does not equal zero'
.Range("C" & iRow).value = Me.Controls("COMBOBOX" & x).Text 'multiple UOM's'
.Range("D" & iRow).value = Me.Controls("TEXTBOX" & x).Text 'multiple lenght's'
End If
Next x
.Range("E" & iRow).value = UserForm1.ComboBox6.Text
.Range("F" & iRow).value = UserForm1.ComboBox8.Text
.Range("G" & iRow).value = UserForm1.ComboBox11.Text
.Range("H" & iRow).value = UserForm1.ComboBox12.Text
.Range("i" & iRow).value = UserForm1.ComboBox19.Text
.Range("j" & iRow).value = ": " & Environ("USERNAME")

End With
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
It looks like you are putting all those combobox values in the same two cells.
If you want a different row for each non-zero entry in those 19 comboboxes, you need to put all the writing code inside the loop.

VBA Code:
Dim x As Long
With ThisWorkbook.Sheets("DATA")
    For x = 31 to 50
        If Me.Controls("COMBOBOX" & x).Text <> 0 And Me.Controls("TEXTBOX" & x) <> 0 Then 'only pull information that does not equal zero'
            iRow = .Range("A1048576").End(xlUp).row + 1
            .Range("A" & iRow).value = iRow - 1
            .Range("B" & iRow).value = UserForm1.ComboBox4.Text
            .Range("C" & iRow).value = Me.Controls("COMBOBOX" & x).Text 'multiple UOM's'
            .Range("D" & iRow).value = Me.Controls("TEXTBOX" & x).Text 'multiple lenght's'
            .Range("E" & iRow).value = UserForm1.ComboBox6.Text
            .Range("F" & iRow).value = UserForm1.ComboBox8.Text
            .Range("G" & iRow).value = UserForm1.ComboBox11.Text
            .Range("H" & iRow).value = UserForm1.ComboBox12.Text
            .Range("i" & iRow).value = UserForm1.ComboBox19.Text
            .Range("j" & iRow).value = ": " & Environ("USERNAME")
        End If
    Next x
End With
 
Upvote 0
For x = 31 To 50
Do you have 20 combos and 20 textboxes, numbered from combo31 to combo50 and textbox31 to textbox50?


.Range("C" & iRow).value = Me.Controls("COMBOBOX" & x).Text 'multiple UOM's'
.Range("D" & iRow).value = Me.Controls("TEXTBOX" & x).Text 'multiple lenght's'
Where do you want to put the content of combo1 and where the content of textbox1.
Where do you want to put the content of the combo2 and where the content of the textbox2
Where combo3 and textbox3?
Etc...
 
Upvote 0
1590190399746.png


the code worked but instead of yielding just the two entries I choose it's yielding back all twenty option including the zeros or nulls.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,543
Latest member
MartinLarkin

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