Results 1 to 9 of 9

Thread: Sleeper: How can I automate arranging cell values by repeating and transposing values

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Administrator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,302
    Location
    Yes, we can omit the first Dim - I get carried away with declaring at times. I create my dim's before I write the code sometimes - as I did with this code.

    Sub test()    
        Dim rng As Range, var As Variant, x As Long, y As Long, z As Long
        
        Set rng = Sheet1.UsedRange
        Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)
        var = rng.Value
        ReDim oVar((UBound(var)) * (UBound(var, 2) - 1) - 1, 1)
        
        For x = 1 To UBound(var)
            For y = 2 To UBound(var, 2)
                oVar(z, 0) = var(x, 1)
                oVar(z, 1) = var(x, y)
                z = z + 1
            Next y
        Next x
        
        Sheet2.Range("A2").Resize(UBound(oVar) + 1, UBound(oVar, 2) + 1) = oVar
    End Sub
    may as well share the file I was playing with for reference, attached.
    Attached Files Attached Files
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2408, Build 17928.20080

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •