+ Reply to Thread
Results 1 to 6 of 6

Transpose/Iterate Group Label to a Row Label

  1. #1
    Registered User
    Join Date
    06-22-2011
    Location
    U.S. Central Time Zone
    MS-Off Ver
    Excel 2007
    Posts
    3

    Transpose/Iterate Group Label to a Row Label

    [SOLVED]
    Help!
    My goal is to create a script or macro to take the "Group" type and add it as a column to the left -- see example below. In these examples I could then sort by Color to demonstrate the flexibility in the data. NOTE: there can be more "Groups", it is not just limited to 2 as shown in this example however the blank lines and format is consistent throughout.

    Thoughts on the best approach to iterate/associate the Group name by row instead? The "." is used to assist with this posting to ensure my column/row examples line up...

    Column A is blank here...
    .....A......B......C......D...... E
    1. ...... BLUE
    2. .......Ball
    3. .......Pale
    4. .......Book
    5. .................
    6. .......Number Blue=3
    7. ..................
    8. .......RED
    9. .......Sign
    10. ......Cup
    11. ......Door
    12. ......Car
    13. ......Poster
    14. ....................
    15. ..... Number Red=5

    To now have my data have a 1-to-1 association and remove the grouping to perform pivots and other preferred ways to use the data, the final output would look like this essentially removing the grouping and label each row with the previous group value:

    Column A would then become the Group Value
    .....A......B......C......D.....E
    1. BLUE....Ball
    2. BLUE....Pale
    3. BLUE....Book
    4. RED.....Sign
    5. RED.....Cup
    6. RED.....Door
    7. RED.....Car
    8. RED.....Poster
    Last edited by Rumble; 06-27-2011 at 10:58 AM. Reason: [SOLVED]

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

    Re: Transpose/Iterate Group Label to a Row Label

    Hello Rumble,

    Welcome to the Forum!

    This macro will transpose the labels based on your sample. Copy the macro into a standard VBA module in your workbook.

    Please Login or Register  to view this content.

    Adding the Macro (Excel 95 - 2003)
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    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!)

  3. #3
    Registered User
    Join Date
    06-22-2011
    Location
    U.S. Central Time Zone
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Transpose/Iterate Group Label to a Row Label

    Quote Originally Posted by Leith Ross View Post
    Hello Rumble,

    Welcome to the Forum!

    This macro will transpose the labels based on your sample. Copy the macro into a standard VBA module in your workbook.

    Please Login or Register  to view this content.

    Adding the Macro (Excel 95 - 2003)
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    SOLVED -- EXCELLENT - after adding the line "Dim I As Long" it worked perfect. This gives me an approach for a much more complex scenario (varied number of lines between Group name etc.). Thank you!

  4. #4
    Registered User
    Join Date
    06-22-2011
    Location
    U.S. Central Time Zone
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Transpose/Iterate Group Label to a Row Label

    I have spent some time on reworking the code but have not been able to accommodate more than one column of data, what if my data has more than one column? Using the same example:

    Column A is blank here...
    .....A......B...........C................D............... E
    1. ...... BLUE..............................................
    2. .......Ball.........Kmart..............................
    3. .......Pale........Target.............................
    4. .......Book.......Bookstar.........................
    5. ...........................................................
    6. .......Subtotal3.....................................
    7. ..........................................................
    8. .......RED.............................................
    9. .......Sign......BannerInc........................
    10. ......Cup......Safeway..........................
    11. ......Door.....Lowes.............................
    12. ......Car.......CarMax...........................
    13. ......Poster...SportsInc........................
    14. ........................................................
    15. ..... Subtotal5....................................

    To now have my data have a 1-to-1 association and remove the grouping to perform pivots and other preferred ways to use the data, the final output would look like this essentially removing the grouping and label each row with the previous group value:

    Column A would then become the Group Value
    .....A..........B.............C.................D..................E
    1. BLUE....Ball......Kmart
    2. BLUE....Pale.....Target
    3. BLUE....Book....Bookstar
    4. RED.....Sign......BannerInc
    5. RED.....Cup......Safeway
    6. RED.....Door......Lowes
    7. RED.....Car........CarMax
    8. RED.....Poster....SportsInc

    Thank you so much for the last quick response!

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

    Re: Transpose/Iterate Group Label to a Row Label

    Hello Rumble,

    I will need to make a few adjustments to macro to determine the number of columns used and regroup the data.

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

    Re: Transpose/Iterate Group Label to a Row Label

    Hello Rumble,

    Here is the updated macro. You can use as many columns as you need now.
    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)

Tags for this Thread

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