+ Reply to Thread
Results 1 to 8 of 8

Convert Single Pair of Columns to 3 Column (Pair) List

  1. #1
    Forum Contributor
    Join Date
    02-24-2008
    Location
    UK
    MS-Off Ver
    2012 and 2016
    Posts
    123

    Convert Single Pair of Columns to 3 Column (Pair) List

    I want to convert a list of names and values listed as follows:

    NAME AMOUNT
    Name1 Value1
    Name2 Value2
    Name3 Value3
    Name4 Value4
    Name5 Value5
    Name6 Value6
    Name7 Value7
    Name8 Value8

    etc

    into 3 pairs of equal length columns with headers



    NAME AMOUNT NAME AMOUNT NAME AMOUNT
    Name1 Value1 Name43 Value43 Name76 Value76
    Name2 Value2 Name44 Value44 Name77 Value77
    Name3 Value3 Name45 Value45 Name78 Value78
    Name4 Value4 Name46 Value46 Name79 Value79
    Name5 Value5 Name47 Value47 Name80 Value80
    Name6 Value6 Name48 Value48 Name81 Value81
    Name7 Value7 Name49 Value49 Name82 Value82
    Name8 Value8 Name50 Value50
    etc etc remainder in 3rd column

    I am able to determine the number of rows in each column by using the Int and Mod function after counting the number of entries in the original list.

    Sub ThreeColumns()

    Dim ThreeColums() As Variant
    Dim Rows As Long, Columns As Long


    Sheet1.Activate ' to ensure we are on the correct worksheet

    Rows = Range("A1", Range("A1").End(xlDown)).Cells.Count - 1
    Columns = Range("A1", Range("A1").End(xlToRight)).Cells.Count - 1

    ReDim ThreeColumns(0 To Rows, 0 To Columns)

    Etc.....

    End Sub

    I can figure out how to find the length of each column using the Int and Mod process on the Rows value but I cannot figure out the the code to read the original pairs of values from the list and then write these values into the 3 column pairs shown above.

    I would be grateful if someone would kindly help.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,942

    Re: Convert Single Pair of Columns to 3 Column (Pair) List

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 02-03-2017 at 05:48 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    02-24-2008
    Location
    UK
    MS-Off Ver
    2012 and 2016
    Posts
    123

    Re: Convert Single Pair of Columns to 3 Column (Pair) List

    Thank you for your speedy response. It is late here in the UK and so I will give it a go over the weekend and let you know the outcome.

  4. #4
    Forum Contributor
    Join Date
    02-24-2008
    Location
    UK
    MS-Off Ver
    2012 and 2016
    Posts
    123

    Re: Convert Single Pair of Columns to 3 Column (Pair) List

    I used the code to produce the result shown in the attached file ThreeColumns1.jpg
    I tried to change the code to produce the result that I actually want in attached file ThreeColumns2.jpg
    but without much success. Sadly my knowledge of the more advanced VBA code that you used is lacking.

    I would be grateful if you would amend the code to:

    1. Copy the Name and Subs values from cells starting on Row 8 (for example)
    2. Copy and write the Name and Subs values starting at Row 9 and writing them into 3 columns with labels to produce the desired result (Three Columns2.jpg)
    3. Change the column widths to set values as shown in ThreeColumns2.

    Many thanks for providing the original code and I hope I am not asking too much for the additional modifications to the code.
    Attached Images Attached Images

  5. #5
    Forum Contributor
    Join Date
    02-24-2008
    Location
    UK
    MS-Off Ver
    2012 and 2016
    Posts
    123

    Re: Convert Single Pair of Columns to 3 Column (Pair) List

    I have tried to do a bit more coding to simplify (in my mind) what is going on in the VBA code.
    I have managed to read the long list of values and write a selected part of the array to a new column
    as shown in ThreeColums2.jpg.

    I have arbitrarily chosen numbers for ColARowStart = 0 and ColARowEnd = 15 as shown in the attached file
    ThreeColumns3.jpg but will use the INT function later to obtain the values for Columns A, B and C.

    I am thinking along the lines of copying the code for Column A and adding code below for Columns B and C. What do I need to do to the code to read and write the values for Columns B and C?

    Hence code that will allow the flexibility to read any set of values from an array of values and place these in a number of columns, with headers, would be ideal.
    Attached Images Attached Images
    Last edited by kencoburn; 02-05-2017 at 06:44 PM. Reason: Added Content

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,942

    Re: Convert Single Pair of Columns to 3 Column (Pair) List

    Try this - for headers that start in cell B8:

    Change

    lngHeaderRow = 8
    strCol = "B"

    to whatever cell they actually start in....

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-24-2008
    Location
    UK
    MS-Off Ver
    2012 and 2016
    Posts
    123

    Re: Convert Single Pair of Columns to 3 Column (Pair) List

    I am sorry that it has taken some time to respond to this topic - I have been away on holiday. I used your revised code and it worked. Many thanks for your assistance.

  8. #8
    Forum Contributor
    Join Date
    02-24-2008
    Location
    UK
    MS-Off Ver
    2012 and 2016
    Posts
    123

    Re: Convert Single Pair of Columns to 3 Column (Pair) List

    I have finally got round to solving the problem with your assistance. I used the
    following VBA code to generate 3 equal sized columns from a long list (one column).

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Merging two single column tables creating a new row for each pair
    By nigelbloomy in forum Excel General
    Replies: 5
    Last Post: 08-15-2016, 08:08 PM
  2. Replies: 3
    Last Post: 07-20-2012, 07:29 PM
  3. How to compare two pair columns and insert value from another column
    By dareme in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2010, 01:08 AM
  4. pair single column to multiple column
    By Ross in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 03:05 AM
  5. [SOLVED] pair single column to multiple column
    By Ross in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 01:05 AM
  6. [SOLVED] pair single column to multiple column
    By Ross in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 12:05 AM
  7. pair single column to multiple column
    By Ross in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-05-2005, 10:05 PM

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