Populating Cells using VBA
What about this, as a first stab... I don't know how you define your Row,
Unit, Shelve and Position numbers, so I simply assumed it's all right to hard
code them into the VBA macro.
Also, the macro assumes (as is indicated in your example) that none of the
numbers will be greater than 99.
===========================
Private Sub FillRows()
Dim iaRows() As Variant
Dim iaUnits() As Variant
Dim iaShelves() As Variant
Dim iaPositions() As Variant
' TODO: Fill out the proper values here
iaRows = Array(1, 2, 3, 4)
iaUnits = Array(99, 88, 77, 66, 55)
iaShelves = Array(12, 34, 56, 78, 90)
iaPositions = Array(9, 8, 7)
' TODO: You have to decide in which order
' the loops should iterate. Rearrange...
Dim x As Long
x = 3
For Each r In iaRows
For Each u In iaUnits
For Each s In iaShelves
For Each p In iaPositions
Cells(x, 1).Value = BuildValue(r, u, s, p)
x = x + 1
Next p
Next s
Next u
Next r
End Sub
Private Function BuildValue( _
ByVal r As Integer, _
ByVal u As Integer, _
ByVal s As Integer, _
ByVal p As Integer) As String
BuildValue = _
Format(r, "00") & "-" & _
Format(u, "00") & "-" & _
Format(s, "00") & "-" & _
Format(p, "00")
End Function
===========================
"williamr" wrote:
I have a small "Do While" VBA program that creates some numbers (4750). The
problem is that I don't know how to populate the cells in the worksheet using
the VBA code. My results look like the following:
Row 1 Unit 2 Shelf 4 Position 5
There are 4750 different combinations. I want to concatenate the number so
they look like 01-02-04-05 in Col A starting in row 3 until the Macro is
done, can someone help?
Thanks in Advance.
|