+ Reply to Thread
Results 1 to 8 of 8

*UPDATE* Rows of data to Columns of data *UPDATE*

Hybrid View

a6ela *UPDATE* Rows of data to... 05-03-2010, 11:04 PM
rylo Re: Rows of data to Columns... 05-03-2010, 11:47 PM
Leith Ross Re: Rows of data to Columns... 05-04-2010, 12:06 AM
laaview Re: Rows of data to Columns... 05-04-2010, 12:29 AM
a6ela Re: Rows of data to Columns... 05-04-2010, 01:01 AM
a6ela Re: *UPDATE* Rows of data to... 05-04-2010, 03:00 AM
Leith Ross Re: *UPDATE* Rows of data to... 05-04-2010, 03:46 AM
Leith Ross Re: *UPDATE* Rows of data to... 05-04-2010, 11:30 AM
  1. #1
    Registered User
    Join Date
    05-03-2010
    Location
    Adelaide
    MS-Off Ver
    Excel 2003
    Posts
    3

    Exclamation *UPDATE* Rows of data to Columns of data *UPDATE*

    Thanks for the help so far, thou a slight change......

    So far the VBS works fine BUT needs to be altered, something a little more advanced.
    it was quite easy to understand how the VBS pulls the data but how can it skip a column of data and a column to add the number "000" to the front of the accountID.???

    new test excel file attached.

    thanks once again!!!
    _lex

    -------------------------------------------------------------------------------------------------------------
    Hi all,

    Such a wonderful site here,
    but for the life of me, i can not work out how to setup a Macro or VBS to convert my simple rows of data to making it columns of data.

    Problem is:
    a) program scans 3x fields of data in (per page), then out puts it to a excel file.
    b) each field is on a different row i.e. name\date\code.
    c) each other page continues after the last row.
    d) 100 pages are scanned in.

    Question being, is there a easy way to output this data so it reads\shows in Columns rather than Rows.

    Any bit of help would go along way!

    Attached is a dummy file which shows the way the data is entered and how it should look like in the end.

    thanks for your time!
    Attached Files Attached Files
    Last edited by a6ela; 05-04-2010 at 02:49 AM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Rows of data to Columns of data

    Hi

    The above can be obtained using formulas.

    E1: =IF((ROW()-1)*3>=COUNTA(A:A),"",OFFSET($A$1,(ROW()-1)*3,0))
    F1: =IF(E1="","",OFFSET($A$1,((ROW()-1)*3)+1,0))
    G1: =IF(E1="","",OFFSET($A$1,((ROW()-1)*3)+2,0))

    Copy down to match the relevant data.

    If you do really need a macro then try

    Sub aaa()
      outrow = 1
      For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row Step 3
        Cells(outrow, "E").Value = Cells(i, 1).Value
        Cells(outrow, "F").Value = Cells(i + 1, 1).Value
        Cells(outrow, "G").Value = Cells(i + 2, 1).Value
        outrow = outrow + 1
      
      
      Next i
      
    End Sub

    HTH

    rylo
    Last edited by rylo; 05-03-2010 at 11:50 PM.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Rows of data to Columns of data

    Hello a6ela,

    Here is an automated VBA solution. The macro below copies the data in column "A" three rows at a time to columns "E:G" as single rows. A button has been added to the worksheet to run the macro.
    Sub RowsToColumns()
    
      Dim Cell As Range
      Dim Data() As Variant
      Dim N As Long, R As Long
      Dim Rng As Range
      Dim RngEnd As Range
      Dim Wks As Worksheet
      
        Set Wks = Worksheets("Sheet1")
        
        Set Rng = Wks.Range("A1")
        Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
        Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))
        
        ReDim Data(1 To Rng.Rows.Count, 1 To 3)
        
          For R = 1 To Rng.Rows.Count Step 3
            N = N + 1
            Data(N, 1) = Rng.Item(R)
            Data(N, 2) = Rng.Item(R + 1)
            Data(N, 3) = Rng.Item(R + 2)
          Next R
          
        Wks.Range("E1:G1").Resize(UBound(Data, 1), UBound(Data, 2)).Value = Data
          
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    06-28-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Rows of data to Columns of data

    Hi
    Apply this code to attached sample file, if you find this to be working then you can make necessary changes in your original file.
    Sub R2C()
    Dim i As Integer               'Captures Number of Rows
    Dim j As Integer                'for each row loop has to run for three times as Each set is of three columns data
    Dim Rw As Integer            ' Row in which data is to be displayed
    Dim Co As Integer            'Column in which data is to be displayed
    
    Rw = 10
    i = 1
        While i <= Selection.Rows.Count 'You need to select the data area 1st then execute the macro.
        Co = 5
                For j = 1 To 3
                ActiveSheet.Cells(Rw, Co).Value = ActiveSheet.Cells(i, 1).Value
                        Co = Co + 1
                        i = i + 1
                Next
        Rw = Rw + 1
        Wend
    MsgBox "Done"
    End Sub
    Hope this helps..
    Last edited by Leith Ross; 05-04-2010 at 01:45 AM. Reason: Added Code Tags

  5. #5
    Registered User
    Join Date
    05-03-2010
    Location
    Adelaide
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Rows of data to Columns of data

    Damn you guys are quick,

    Thanks heaps for the kind help it was greatly appreciated!!
    thou went with Leith's VBS. works like a dream :-)

    cheers

  6. #6
    Registered User
    Join Date
    05-03-2010
    Location
    Adelaide
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: *UPDATE* Rows of data to Columns of data *UPDATE*

    Thanks for the help so far, thou a slight change......

    So far the VBS works fine BUT needs to be altered, something a little more advanced.
    it was quite easy to understand how the VBS pulls the data but how can it skip a column of data and a column to add the number "000" to the front of the accountID.???

    new test excel file attached.

    thanks once again!!!
    _lex

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: *UPDATE* Rows of data to Columns of data *UPDATE*

    Hello a6ela,

    You will need to give me an example of the problem or post an updated workbook that has the problem.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: *UPDATE* Rows of data to Columns of data *UPDATE*

    Hello a6ela,

    Here is the revised macro. It now adds a "000" prefix to all the account IDs. The columns have been changed to "J,L,N,O". Here is the code that has been added to the attached workbook.
    Sub RowsToColumns()
    
      Dim Cell As Range
      Dim N As Long, R As Long
      Dim Rng As Range
      Dim RngEnd As Range
      Dim Wks As Worksheet
      
        N = 2
        Set Wks = Worksheets("Sheet1")
        
        Set Rng = Wks.Range("A1")
        Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
        Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))
        
        Wks.Columns("J").Cells.NumberFormat = "@"
        
          For R = 1 To Rng.Rows.Count Step 4
            Wks.Cells(N, "J") = "000" & Rng.Item(R).Text
            Wks.Cells(N, "L") = Rng.Item(R + 1)
            Wks.Cells(N, "N") = Rng.Item(R + 2)
            Wks.Cells(N, "O") = Rng.Item(R + 3)
            N = N + 1
          Next R
          
        Wks.Columns("J").NumberFormat = "General"
          
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1