Hi. I have the vba code, but its giving me error when i have 0 and 0 in column A and B. Was wondering anyone can help with this??
Sub RepeatValues()
Dim x As Range, SelectedRange As Range, OutputRange As Range
Range("E:F").ClearContents
Range("E1:F1").Value = [{"Result","Sorted Data"}]
Set SelectedRange = Application.Range("A2", Range("A2").End(xlDown).End(xlToRight))
Set OutputRange = Application.Range("E2")
For Each x In SelectedRange.Rows
Occurrence = x.Range("A1").Value
xNumber = x.Range("B1").Value
OutputRange.Resize(Occurrence, 1).Value = xNumber
Set OutputRange = OutputRange.Offset(Occurrence, 0)
Next
Range("E2:F" & Range("E" & Rows.Count).End(xlUp).Row).FillRight
Range("F1", Range("F1").End(xlDown)).Sort Key1:=Range("F1"), Order1:=xlAscending, Header:=xlYes
'MsgBox "A new list has been created in E column with data repeated multiple times and sorted data in F column.", vbOKOnly, "Excel by Romeo Costillas"
End Sub
Sub RepeatValues()
Dim x As Range, SelectedRange As Range, OutputRange As Range
Range("E:F").ClearContents
Range("E1:F1").Value = [{"Result","Sorted Data"}]
Set SelectedRange = Application.Range("A2", Range("A2").End(xlDown).End(xlToRight))
Set OutputRange = Application.Range("E2")
For Each x In SelectedRange.Rows
Occurrence = x.Range("A1").Value
xNumber = x.Range("B1").Value
OutputRange.Resize(Occurrence, 1).Value = xNumber
Set OutputRange = OutputRange.Offset(Occurrence, 0)
Next
Range("E2:F" & Range("E" & Rows.Count).End(xlUp).Row).FillRight
Range("F1", Range("F1").End(xlDown)).Sort Key1:=Range("F1"), Order1:=xlAscending, Header:=xlYes
'MsgBox "A new list has been created in E column with data repeated multiple times and sorted data in F column.", vbOKOnly, "Excel by Romeo Costillas"
End Sub
Purchase Order and Budget Estimation.xlsm | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | Occurrence | xNumber | Result | Sorted Data | ||||
2 | 0 | 0 | ||||||
3 | 20 | A131231 | ||||||
4 | 20 | A121213 | ||||||
5 | 2 | ADS151561 | ||||||
6 | 2 | ADDS131312 | ||||||
7 | 20 | 1515615616 | ||||||
8 | 1 | 15134684614 | ||||||
9 | 1 | 15164651 | ||||||
10 | 20 | 561561511 | ||||||
11 | 1 | 456456456156132132 | ||||||
12 | 0 | 0 | ||||||
13 | 0 | 0 | ||||||
14 | 0 | 0 | ||||||
Check In Item |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A2:A14 | A2 | ='PO Item'!Q3 |
B2:B14 | B2 | ='PO Item'!V3 |