View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JK JK is offline
external usenet poster
 
Posts: 78
Default Filling a WS from a UserForm

I am using a UF to fill a WS with unit count and product. For example, 2
Widgets, 2 Gadgets, 2 Gidgets should fill as follows:
1 Widget
2 Widget
3 Gadget
4 Gadget
5 Gidget
6 Gidget
The following code works:
Private Sub CommandButton1_Click()

Dim myCell As Range

Set myCell = ActiveSheet.Range("A1")

Dim j As Long, k As Long, i As Long

ActiveSheet.Range("A1:B15").Value = ""

On Error Resume Next

j = 0

For k = 1 To 10 Step 2

For i = 1 To CLng(UserForm1.Controls("TB" & k).Text)

j = j + 1

myCell.Offset(j - 1, 0).Value = j

myCell.Offset(j - 1, 1).Value = _

UserForm1.Controls("TB" & k + 1).Text

Next i

Next k

myCell.Select

On Error GoTo 0

End Sub

However, my UF allows a unit count for up to 5 products. So when I enter
only the 3 products (Widget, Gadget, Gidget) the WS looks like this:

1 Widget

2 Widget
3 Gadget
4 Gadget
5 Gidget
6 Gidget
7
8
How can I correct the code to only count the 3 products entered?
Also (if I'm not pushing my luck), I would prefer to use a TB for the unit
count only, and a list box for the product. If a code can be written for
that, I would very much help with that also.
Thank you in advance.
Jim Kobzeff