Forum Discussion

RoweeYadin's avatar
RoweeYadin
Copper Contributor
Aug 06, 2021

trying this code am i missing something I can't get it to work?

Function transposeRange(Rg As Range)
'Created to put all dynamic values in one column inside one row in one cell
Dim xCell As Range
Dim xStr As Range
For Each xCell In Rg
If Not IsEmpty(xCell.Value) Then
xStr = xStr & xCell.Value & ","
End If
Next
transposeRange = Left(xStr, Len(xStr) - 1)
End Function

2 Replies

  • JMB17's avatar
    JMB17
    Bronze Contributor
    You need to declare xStr as string, not range. But, if you have office 2016 or higher, you should check if you have the built-in textjoin function, which I believe will do what you need.
  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    RoweeYadin Not sure what you want to achieve, but by the name of the function you want to transpose a range, Are you aware that there is a function called TRANSPOSE? Depending on your Excel version you may have to enter it with Ctrl-Shift-Enter, rather than jus Enter.

Resources