Fill multiple rows according to a value in a TextBox

epardo87

Board Regular
Joined
Feb 24, 2015
Messages
56
Hello, well I have a UF working but each entry fills only one row, the problem is that I can't always place a single row of certain Item with a qty=4 (e.g.), instead I could need four rows with qty=1 each, or two rows with Qty 2, etc. (it varies according to the item).

So I need a TextBox where the number defines the maximum Qty so if I place QTY=4 and MaxQty = 1, then it transfers data to four rows with Qty= 1 (also require that if odd number, the last one contains fewer qty to avoid fractions)...

I'd really appreciate any help!

So this is the code, a little bit simplified, suppose that the new field is called MaxQtyTextBox
Code:
Private Sub RegCommandButton_Click()
Dim emptyRow As Long
Sheet2.Activate
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Dim bControlEmpty As Boolean
bControlEmpty = False

    If Len(ItemComboBox.Value) > 0 Then
    Cells(emptyRow, 3).Value = ItemComboBox.Value
    Else
    bControlEmpty = True
    End If
    If Len(QtyTextBox.Value) > 0 Then
    Cells(emptyRow, 4).Value = QtyTextBox.Value
    Else
    bControlEmpty = True
    End If
    
If bControlEmpty Then
    MsgBox "Please complete all fields"
Else
    
    Cells(emptyRow, 1).Value = Date
[COLOR=#ff0000]'This is the code for the consecutive number, don't know if would be affected by the Max Qty TextBox[/COLOR]
    With Cells(emptyRow, 2)
    .Value = Cells(emptyRow - 1, 2).Value + 1
    End With    
 End If
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.
Hi,
If I'm understanding your requirement, where you have

.Value = Cells(emptyRow - 1, 2).Value + 1

could you amend that to

.Resize(QtyTextBox.Value).Value = Cells(emptyRow - 1, 2).Value + 1

I haven't tried this but...

Not sure about the "odd number" requirement. Maybe an "If cell.value Mod 2 = 1 then" test and modify QtyTextBox.value accordingly?
 
Upvote 0

Forum statistics

Threads
1,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

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