Results 1 to 7 of 7

Thread: VBA To Split A Group Or Set Of Data In Rows In To Columns

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0

    VBA To Split A Group Or Set Of Data In Rows In To Columns

    i have a sheet that has many columns and i want to sort them i attached an example sheet 2 is the sheet that must be changed in to sheet one
    Attached Files Attached Files
    Last edited by CORAL; 04-09-2014 at 02:20 PM.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Try this
    Code:
    Sub ColumnizeExcelFox()
    
        Dim lngLast As Long
        Const clngCol As Long = 2
        
        Worksheets("Sheet2").UsedRange.Clear
        With Worksheets("Sheet1")
            lngLast = .Cells(.Rows.Count, 1).End(xlUp).Row
            Do Until lngLast <= 1
                .Range(.Cells(lngLast, 1).End(xlUp)(0), .Cells(lngLast, clngCol)).Copy Worksheets("Sheet2").Cells(1)
                lngLast = .Cells(lngLast, 1).End(xlUp).Row - 2
                If lngLast > 0 Then
                    Worksheets("Sheet2").Cells(1).Resize(, clngCol).EntireColumn.Insert
                End If
            Loop
        End With
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    Please use puctuation marks in your posts.

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Could you please clarify that, snb. Not sure what you were referring to.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0
    hi Mr
    your code change sheet 1 in to sheet 2 but i want the code for changing sheet 2 into sheet 1
    so i think(not sure) the subject should be changed in to:
    "VBA To Split A Group Or Set Of Data In columns In To row"
    Last edited by CORAL; 04-11-2014 at 08:09 AM.

  6. #6
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    12
    Code:
    Sub blah()
    Set SceSht = ActiveSheet
    Set NewSht = Sheets.Add(after:=Sheets(Sheets.Count))
    Set Destn = NewSht.Cells(1, 1)
    Application.Goto Destn
    
    With SceSht
      lc = .Cells(1, .Columns.Count).End(xlToLeft).Column
      For i = 1 To lc Step 2
        Set RngToCopy = Intersect(.UsedRange, .Cells(1, i).Resize(, 2).EntireColumn)
        RngToCopy.Copy Destn
        Set Destn = Destn.Offset(RngToCopy.Rows.Count)
        Application.Goto Destn
      Next i
    End With
    NewSht.Columns("A:B").AutoFit
    End Sub
    Acts on the active sheet as the source sheet, creates a new sheet.
    The values seem to be be awry on your sheet 1.

  7. #7
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    12
    I've just realised that I left 2 debug lines in which don't need to be there; they are the 2 lines:
    Application.Goto Destn
    Delete them.

Similar Threads

  1. Replies: 3
    Last Post: 02-24-2014, 05:48 AM
  2. Replies: 10
    Last Post: 02-18-2014, 01:34 PM
  3. Replies: 10
    Last Post: 08-31-2013, 06:56 PM
  4. Replies: 4
    Last Post: 05-01-2013, 09:49 PM
  5. Replies: 2
    Last Post: 03-05-2013, 07:34 AM

Posting Permissions

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