ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   how to convert an array (https://www.excelbanter.com/excel-discussion-misc-queries/58814-how-convert-array.html)

newengland

how to convert an array
 

Hi

I have an array of values as follows

3 25
1 10
4 12
6 7

the first column represents the number of instances of the row. I
would like to convert this as follows:

25
25
25
10
12
12
12
12
7
etc.

how can I do this formulaically? or formulaically with a UDF?

thanks


--
newengland
------------------------------------------------------------------------
newengland's Profile: http://www.excelforum.com/member.php...fo&userid=5946
View this thread: http://www.excelforum.com/showthread...hreadid=490855


[email protected]

how to convert an array
 
Hello,

A suggestion for a UDF:
Option Explicit

Function one_dim_array(rI As Range) As Variant
'Converts an argument array of frequencies and values into
'a one-dimensional array.
'Example:
'3 25
'1 10
'4 12
'6 7
'will become 25 25 25 10 12 12 12 12 7 7 7 7 7 7.
'Remember to select sufficient count of cells for result
'and to enter function as array-formula (CTRL + SHIFT + ENTER).
Dim vR As Variant
Dim r As Range
Dim b As Boolean
Dim lF As Long, i As Long, j As Long

With Application.Caller

ReDim vR(1 To .Rows.Count, _
1 To .Columns.Count)
i = 1
j = 1
b = True
For Each r In rI
If b Then
lF = r.Value
Else
Do While lF 0
vR(i, j) = r.Value
j = j + 1
If j .Columns.Count Then
j = 1
i = i + 1
End If
lF = lF - 1
Loop
End If
b = Not b
Next r

End With

one_dim_array = vR

End Function

HTH,
Bernd



All times are GMT +1. The time now is 01:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com