Insert new row with data

pacov

New Member
Joined
Jul 22, 2016
Messages
2
I want to insert new row with data from textboxes in userform. For example, before clicking on button in userform Sheet1 loooks like this:
A2
NAME
PRICE
A3
GROUP 1
X
A4
GROUP 2
X

<tbody>
</tbody>
But after clicking button on userform Sheet1 I would to achieve this:
A2
NAME
PRICE
A3
GROUP 1
X
A4
TEXTBOX1.VALUE
TEXTBOX2.VALUE
A5
GROUP 2
X

<tbody>
</tbody>

The new row will be inserter bellow group 1 or group 2 depending by value of dropmenu (Group 1, Group 2) in userform. Can you help me
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try something like this. The "dropdown" is ComboBox1

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] CommandButton1_Click()
    [color=darkblue]Dim[/color] Found [color=darkblue]As[/color] Range
    [color=darkblue]If[/color] Me.ComboBox1.Value <> "" [color=darkblue]Then[/color]
        [color=darkblue]Set[/color] Found = Range("A:A").Find(What:=Me.ComboBox1.Text, _
                                      LookIn:=xlValues, _
                                      LookAt:=xlWhole, _
                                      MatchCase:=False)
        [color=darkblue]If[/color] [color=darkblue]Not[/color] Found [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
            Found.Offset(1).EntireRow.Insert
            Found.Offset(1).Resize(, 2).Value = Array(Me.TextBox1.Text, Me.TextBox2.Text)
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,700
Members
449,464
Latest member
againofsoul

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