Userform entries to be inserted in section of row range

sanilmathews

Board Regular
Joined
Jun 28, 2011
Messages
102
I have the below code which gets input from the user and inserts to a sheet called Dashboard. The bolded line of code perfectly starts from the first empty row and then work its way down for each entry.

Is there any possibility of doing the below?

Combobox1 will have 3 selection for the user. Based on the selection made in Combobox1 the data needs to be inserted into 3 specific range of rows.

For selection1, the entry would start from Row 2 and work its way down until Row 30
For selection2, the entry would start from Row 32 and work its way down until Row 40
For selection3, the entry would start from Row 42 and work its way down until Row 50 or beyond

Code:
Private Sub Add()
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Dashboard")

[B]lRow = ws.Cells(Row.Count, 1).End(xlUp).Offset(1, 0).Row
[/B]
With ws
    .Cells(lRow, 1).Value = Me.txtdate.Value
    .Cells(lRow, 2).Value = Me.Combobox1.Value
    .Cells(lRow, 3).Value = Me.Combobox2.Value
    .Cells(lRow, 4).Value = Me.Combobox3.Value
    .Cells(lRow, 5).Value = Me.Combobox4.Value
End With


Me.txtdate.Value
Me.Combobox1.Value = ""
Me.Combobox2.Value = ""
Me.Combobox3.Value = ""
Me.Combobox4.Value = ""
Unload Me
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try
Code:
lRow = Choose(Me.ComboBox1.Value, 2, 32, 42)
 
Upvote 0

Forum statistics

Threads
1,215,364
Messages
6,124,509
Members
449,166
Latest member
hokjock

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