I am VERY new to VBA.
I am trying to build a UDF function to parse comma delimited text in a cell into rows. I have a Sub that works fine, but requires a manual "run"; I want it to be a function.
Say I have in cell A1 the following string comma delimited string
M89-76,M64-62,M76-80
and I want to list each M... in a separate row cell. The sub code accomplishes this but requires a manual run; I need a UDF of the sub code so I can type =myUDF(A1) into B1 and the list of M...'s is returned in cells B1 through B3
Sub TransposeRange()
Dim rng As Range
Dim InputRng As Range, OutRng As Range
Set InputRng = Application.Selection.Range("A1")
Set InputRng = Application.InputBox("Range(single cell) :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Arr = VBA.Split(InputRng.Range("A1").Value, ",")
OutRng.Resize(UBound(Arr) - LBound(Arr) + 1).Value =
Application.Transpose(Arr)
End Sub
If you are using a verion that supports Dynamic Arrays (Office365) then your UDF can spill the result into as many cells as required.
For data in
Aput=MyUDF(A1)in CellB1, the result will spill downNote that
Application.Transposehas a string length limit of 32765 characters. If the data inA1is longer that that, the result will be truncated. In that case you would need to code the transpose (loops, into a 2D array)If you don't have Dynamic Arrays, the formula will still work when entered as an Array Formula into a range large enought to hold the result (eg
B1:B3)