+ Reply to Thread
Results 1 to 9 of 9

VBA code - I just can't work it out

  1. #1
    Registered User
    Join Date
    12-04-2017
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    16

    VBA code - I just can't work it out

    Hi guys, a while ago someone on here kindly gave me the following code which solved a requirement I had to essentially un-pivot a data table.

    What I now need the code to do is to keep the first five columns but un-pivot the remaining 12 columns so that each row of data has first five columns from the original data and then the column header of the remaining columns followed by the data in the corresponding cell.

    The code below just gives me the first two columns and then the column header and the data and I have spent hours trying to work out what to change to gert the first five columns plus the data.

    If anyone can help me out i'd be so grateful - here's the code

    Please Login or Register  to view this content.
    Thanks for your time and patience

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: VBA code - I just can't work it out

    Quote Originally Posted by Happytab View Post
    Hi guys, a while ago someone on here kindly gave me the following code
    No,it is not what I posted.

    https://www.excelforum.com/excel-pro...ls-in-row.html

  3. #3
    Registered User
    Join Date
    12-04-2017
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    16

    Re: VBA code - I just can't work it out

    Quote Originally Posted by jindon View Post
    Sorry Jindon, I thought I made the changes you suggested in the original thread but I apologise if I offended you in any way.

    I'm just really confused and frustrated right now.

    Again, I apologise.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: VBA code - I just can't work it out

    What you are asking here is not complicated.

    If you upload a workbook showing before/after someone will give you a solution.

    I'll go to sleep soon.

  5. #5
    Registered User
    Join Date
    12-04-2017
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    16

    Re: VBA code - I just can't work it out

    Heres a sample of what I need with before and after. Thanks again
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: VBA code - I just can't work it out

    So after looking this over, its prudent to point out this has Nothing to do with pivot tables.

    Essentially you are looking to transpose columns of a record into additional rows/records.

    IE: record1 col1 col2 col3

    becomes:

    record1 col1
    record1 col2
    record1 col3

    As mentioned not terribly hard, but there are many ways of doing it. Also, as I am sure you are aware, this will result in many more columns than you had in your original data (and less columns). How many rows is your actual data? Do we have to worry about ending up with more rows than is on a single sheet?

    Also judging from your sample does every record have all 12 stages. In other words will each record become 12 records then or is it possible it will vary (one record may only have 3 stages, another 6, some 12, etc)?
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  7. #7
    Registered User
    Join Date
    12-04-2017
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    16

    Re: VBA code - I just can't work it out

    Quote Originally Posted by Zer0Cool View Post
    So after looking this over, its prudent to point out this has Nothing to do with pivot tables.

    Essentially you are looking to transpose columns of a record into additional rows/records.

    IE: record1 col1 col2 col3

    becomes:

    record1 col1
    record1 col2
    record1 col3

    As mentioned not terribly hard, but there are many ways of doing it. Also, as I am sure you are aware, this will result in many more columns than you had in your original data (and less columns). How many rows is your actual data? Do we have to worry about ending up with more rows than is on a single sheet?

    Also judging from your sample does every record have all 12 stages. In other words will each record become 12 records then or is it possible it will vary (one record may only have 3 stages, another 6, some 12, etc)?
    Hi, thanks for your reply.

    In this case I have about 3,000 records in the crosstab - and each record has twelve stages - so I will end up with 36,000 rows

    The problem is that more customers will be added toi the list and I will need to keep doing this conversion as part of other processes which is why I need to work out the vba code to do it.

    Like I said originally, the code above nearly works but iinstead of columns 1 to 5 plus the data I get column 1&2 plus the data.

    I just can't work out what to change in the code to get the desired result.

    thanks again for your help.

  8. #8
    Registered User
    Join Date
    12-04-2017
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    16

    Re: VBA code - I just can't work it out

    OK finally worked it out - thank both for your help.

    Code that finally worked is below - if anyone else happens accross the same issue.
    Please Login or Register  to view this content.
    Thanks again

  9. #9
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: VBA code - I just can't work it out

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ben Van Johnson

+ 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] Setting Print area with VBA code on active sheet - Can't get my code to work
    By hans302 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2017, 05:07 AM
  2. Testing single code, work fine. Put multiple codes in one sheet, one code doesn't work.
    By MayDay1988 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2017, 06:14 PM
  3. Code will not work when followed by more code (does work when stepped through)
    By Cashgenerator in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-03-2015, 10:12 AM
  4. [SOLVED] Need help with VBA code. Tons of code seperated in two, second part of code doesn't work.
    By FragaGeddon in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 11-30-2015, 11:46 AM
  5. Replies: 9
    Last Post: 08-30-2013, 07:49 AM
  6. Replies: 1
    Last Post: 08-14-2013, 12:01 PM
  7. [SOLVED] hELP FOR MY PROJECT (IN PROJECT SHEET CODE NOT WORK,, OUTSIDE THAT CODE WORK)
    By santosh226001 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-06-2013, 06:53 AM

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