Pls help how to Add multiple rows with same value of combobox through userform

Sany_s11

New Member
Joined
Nov 10, 2019
Messages
7
I have created a userform
Which have a combobox and a text box, save button.

Now when i select a value say"ABCD" in combo box, i will mention say number as "5".
Now when i click on save button, then 5 rows of value "ABCD" should be created in excel cells in the column i specify. And next time i select any other value or the same value it should repeat for the next available cell in the same column. and so on.

Please help with the code in VB to achieve this.
 

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.
So you want to always enter the value 5 times?
If not how do you plan to tell the script how many times?

And you said:
excel cells in the column i specify

How do you plan to specify what column?
 
Upvote 0
Assuming you want a Inputbox to ask how many times.
And assuming you want these values entered into column A

And assuming you plan to select the values from a list of values in the ComboBox1

Try this:

Put this script in the ComboBox

Code:
Private Sub ComboBox1_Change()
'Modified  11/10/2019  8:21:44 AM  EST
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1
Dim ans As Long
ans = InputBox("How Many Times")
Cells(Lastrow, 1).Resize(ans).Value = ComboBox1.Value
End Sub
 
Upvote 0
Thank you, it did help by adding rows as expected. But i don`t want a new dialog box to pop up. I have both combobox and input box in the same user form. So i have added a text field below the combobox, after selecting the value in the combobox i will have to mention the number in the text box and once i click save button in the same user form the values should be populated in cells.
 
Upvote 0
How about
Code:
Private Sub CommandButton1_Click()
    Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Me.TextBox1.Value).Value = Me.ComboBox1.Value
End Sub
 
Upvote 0
How about
Code:
Private Sub CommandButton1_Click()
    Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Me.TextBox1.Value).Value = Me.ComboBox1.Value
End Sub


Superb, It worked.... Thanks a lot. I am a new learner may be need help for any more queries.. Thanks a lot
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,165
Members
452,615
Latest member
bogeys2birdies

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