Posted to microsoft.public.excel.misc
|
|
Populate Data In Rows
Rick and Gary,
I apologise for not being specific earlier. Thank you for the new code.
EK
"Rick Rothstein (MVP - VB)" wrote:
Yes, it works. Except that this code also re-sorted the order of the data
in
Col A and B. I would like it sorted Col C by the repeat count and leave
Col A
and B intact. The code from Gary"s Student did just that.
Fixed in the code below.
For this code, what do I have to change in order to re-populate with a
different definition such as:
A=6 times, B=3 times, C=2 times and D=1 time?
You didn't say you would need other encodings, so I (and Gary) created an
algorithm to do exactly what you asked. To make it changeable will require a
different algorithmic approach. Assuming you will need these repeat values
to be changeable, I think the best way to handle it would be to store the
repeat values in cells on the spreadsheet (you can hide the Column so they
are not seen if you wish). For the (new) subroutine code below, I am
assuming the A repeat value will be stored in F1, the B repeat value in F2,
the C repeat value in F3 and the D repeat value in F4.
Sub CreateRepeats()
Dim X As Long
Dim Y As Long
Dim LastRow As Long
Dim LastDataRow As Long
LastDataRow = 1
With ActiveSheet
LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
For X = 1 To LastRow
For Y = 1 To Range("F" & CStr(Asc(.Cells(X, 2).Value) - 64)).Value
Cells(LastDataRow, 3).Value = Cells(X, 1)
LastDataRow = LastDataRow + 1
Next
Next
.Range("C:C").Sort Key1:=.Columns("C")
End With
End Sub
Rick
|