Question

I have a spreadsheet with one column and values as follows:

A
B
C
*
D
E
*
F
G
H
I

The * indicates an empty cell. Is there anyway I can get it to read as the following with each one being in a different cell?

1 2 3
D E
F G H I

I got this =IF(ISBLANK(A12),TRANSPOSE(A13:A23),"") which helps but the range is set to 10. How do set it so it looks for the next empty cell after A13 and backtracks one cell?

Thanks,

JJ

Was it helpful?

Solution

There is no built-in function that can perform this task. I have created a user function that should be able to do the trick. For it to work properly the input data should be in one single column with empty cells defining the "line breaks" of the transposed output matrix.

Include the following code in a VBA module.

Option Explicit
Function TransposeSpecial(InpRng As Range)
    Dim Cell As Range
    Dim c1 As Integer, c2 As Integer, i As Integer, j As Integer, k As Integer
    Dim TArr()

    If TypeName(InpRng) <> "Range" Then Exit Function

    'Get dimentions
    For Each Cell In InpRng
        If Cell.Value <> vbNullString Then
            i = i + 1
        Else
            c1 = c1 + 1
            If i > c2 Then c2 = i
            i = 0
        End If
    Next Cell

    c1 = c1 + 1
    If i > c2 Then c2 = i
    i = 1
    j = 1

    'Defines the dimention of the output array
    ReDim TArr(1 To c1, 1 To c2)

    'Writes to array
    For Each Cell In InpRng
        If Cell.Value <> vbNullString Then
            TArr(i, j) = Cell.Value
            j = j + 1
        Else
            For k = j To c2
                TArr(i, k) = vbNullString
            Next k
            i = i + 1
            j = 1
        End If
    Next Cell
    If j <= c2 Then
        For k = j To c2
            TArr(i, k) = vbNullString
        Next k
    End If

    TransposeSpecial = TArr
End Function

Now, by using this function, with the single data column as input, on a range (at least) big enough to contain the entire output matrix, you should get the desired output. Remember to use Ctrl+Shift+Enter when working with functions that should return a matrix.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top