1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Excel Macro - Rows to Columns

Discussion in 'Business Applications' started by Nemoria, Apr 19, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. Nemoria

    Nemoria Thread Starter

    Joined:
    Apr 19, 2011
    Messages:
    6
    Hi,

    I have data in the following row format:

    0 4591 5 4491 10 4461 15 4441 20 4321

    The data are X and Z points so the above example shows 5 pairs of data. I would like to place these pairs of data sequentially in two columns where one column has all the X's and the other has the related Z's. I have many, many rows of similar data that I need transferred into two columns.

    0 4591
    5 4491
    10 4461
    15 4441
    20 4321

    Could anyone help me out with a macro that can do this for me?

    Thanks very much in advance.
     
  2. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    Welcome to the board.

    Let's say the example pairs are in A1:J1.

    With A1:J1 selected,

    Sub test()
    For Each Cell In Selection
    If Cell.Column Mod 2 = 1 Then
    Range("A" & Rows.Count).End(xlUp).Offset(1) = Cell.Value
    Else
    Range("B" & Rows.Count).End(xlUp).Offset(1) = Cell.Value
    End If
    Next Cell
    End Sub


    gives you actual pairs in A2:B6.

    So, what do we need to adjust to make it compatible with your "many, many rows of similar data" scenario?
     
  3. Nemoria

    Nemoria Thread Starter

    Joined:
    Apr 19, 2011
    Messages:
    6
    Ah, that's exactly what I needed. Thanks very much bomb #21, I appreciate it! Problem solved. :)
     
  4. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    OK. Thanks for marking this "Solved". (y)
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/992309

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice