+ Reply to Thread
Results 1 to 5 of 5

VBA code to resize data to a number of rows

  1. #1
    Registered User
    Join Date
    12-01-2012
    Location
    Nigeria
    MS-Off Ver
    Excel 2007
    Posts
    2

    VBA code to resize data to a number of rows

    Let me try simplify

    Can I get a VBA code to resize this data

    The raw data is in columns A to C and has uneven number of rows but i want to transform to exactly 6 rows and as many columns as are necessary as in the data below

    I also posted on mrexcel.com http://www.mrexcel.com/forum/excel-q...mber-rows.html

    How do I post a workbook here, if at all I can
    Last edited by Momentman; 10-31-2015 at 06:14 AM.

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: VBA code to resize data to a number of rows

    Welcome Momentman.

    You can attach a workbook by editing your original post, or clicking the 'Go Advanced' button and looking for the paperclip icon above the input area.

    I'll start writing up some code to do this for you, if you can provide a sample showing data source and expected output then it will help with testing.

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: VBA code to resize data to a number of rows

    See if this gives the right result

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-01-2012
    Location
    Nigeria
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: VBA code to resize data to a number of rows

    Quote Originally Posted by jason.b75 View Post
    See if this gives the right result
    Very nicely done. It does give the right results and this is similar to what i was able to come up with

    But i have in total over 6million data points, so looping from cell to cell could take a while, so i was thinking if there was a way to kind of avoid that and make it faster

  5. #5
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: VBA code to resize data to a number of rows

    I tested the code with around 250k cells of data and it took about 10 seconds, that was without setting screenupdating to false, etc.

    I can think of ways to do it in 'blocks' but it would need a more cumbersome method, which might be slower, and may not necessarily give the desired output.

    The theory.

    Filter column A in the data source to show only the records that should be copied. Then copy the visible portion of column A to a new sheet.
    Clear the filter and repeat for column B, C, etc.

    Next work with the new sheet.

    Assuming 20 rows specified, cut (not copy) rows 21:40 to next empty column in row 1, repeat for 41:60, etc. until end of data.

    Depending on the number of records copied from each column in the original data source, you could end up with a lot of blanks, re-processing the data to tidy up again could make for a very inefficient process.

+ 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] code to auto number rows - that will update when rows are added/deleted
    By dkitzerow in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-12-2015, 10:45 AM
  2. Code to check the number of rows between last data cell in G and F.
    By Nitefox in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2014, 09:34 PM
  3. [SOLVED] Macro code to insert 3 rows on spreadsheet with variable number of rows
    By D18GE in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-17-2013, 07:33 AM
  4. [SOLVED] Need VBA code to count number of rows & split into group of 7 rows in same sheet
    By amy_d2 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-05-2013, 11:03 AM
  5. [SOLVED] Modify code to transpose a stack of data to rows on to delimit on text hone number field
    By coachtim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-26-2012, 02:52 PM
  6. Code to plot a chart from a data set with a variable number of rows
    By MichaelMcF in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-28-2012, 07:31 PM
  7. VBA code to unhide X number of rows based on a number entered into a cell above
    By gazza365 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2010, 08:48 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