+ Reply to Thread
Results 1 to 9 of 9

Rearrange multiple columns in four columns, VBA

  1. #1
    Registered User
    Join Date
    02-03-2018
    Location
    Stockholm, Sweden
    MS-Off Ver
    Microsoft Excel for Mac, Version: 16.9
    Posts
    6

    Rearrange multiple columns in four columns, VBA

    Hello guys,
    An excel rookie needs the help of more experienced users of Excel and VBA.

    I have a data set that looks the following way:
    SAMPLE.xlsx

    There are around 600 companies in the data set. I would like to arrange those companies and their four columns of data into only four columns. In other words, I want all the data to be arranged only in columns A-D, no data starting from column E. Note: the amount of data for each company differs; I can have 10 years of data for one company, and only 2 months of data for another company.

    I look forward to hearing from you soon. Thank you so much in advance!
    Attached Images Attached Images
    Last edited by eguzun; 02-03-2018 at 09:33 AM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,768

    Re: Rearrange multiple columns in four columns, VBA

    Attach a sample workbook (not image).

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate.

    Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Registered User
    Join Date
    02-03-2018
    Location
    Stockholm, Sweden
    MS-Off Ver
    Microsoft Excel for Mac, Version: 16.9
    Posts
    6

    Re: Rearrange multiple columns in four columns, VBA

    Thank you so much for getting back to me so quickly! I attached an excel file with a BEFORE and AFTER sheet.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,768

    Re: Rearrange multiple columns in four columns, VBA

    Please Login or Register  to view this content.
    Click "RUN" on "After"
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-03-2018
    Location
    Stockholm, Sweden
    MS-Off Ver
    Microsoft Excel for Mac, Version: 16.9
    Posts
    6

    Re: Rearrange multiple columns in four columns, VBA

    Thank you! This is impressive. I do get the following message/error though:

    Run-time error '1004:
    You can't paste this here because the Copy area and paste are aren't the same size.

    Select just one cell in the paste area or an area that's the same size, and try pasting again.

    What to I need to change in the following row: inRng.Copy Destination:=ws2.Cells(lr2, "A") ?

  6. #6
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Rearrange multiple columns in four columns, VBA

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,768

    Re: Rearrange multiple columns in four columns, VBA

    Post file with errors as I don't know why the areas are not the same. Are there merged cells somewhere?

    nRng.Copy Destination:=ws2.Cells(lr2, "A")
    .... where ?

    If you want to start in column other than "A" then change "A" to required column .

    Lesson here: post a file that represent what the real outcome required is.

  8. #8
    Registered User
    Join Date
    02-03-2018
    Location
    Stockholm, Sweden
    MS-Off Ver
    Microsoft Excel for Mac, Version: 16.9
    Posts
    6

    Re: Rearrange multiple columns in four columns, VBA

    I believe I know what the problem might be. My data set is simply too large. The data for approximately 80% of my sample companies is rearranged perfectly using your code (the data reached the maximum of 1,048,576 rows). I will try to use a smaller data set. Thank you so much for your help, John!

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,768

    Re: Rearrange multiple columns in four columns, VBA

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

    EDIT: it should possible to split the into more than one sheet: is that acceptable?

+ 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] Rearrange groups of columns, with multiple rows
    By gromitnz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-16-2017, 04:29 PM
  2. [SOLVED] Format Spreadsheet - split text columns, rearrange columns, conditional format
    By lacke81c in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2015, 11:50 AM
  3. Rearrange columns
    By karthik013 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-03-2014, 05:51 AM
  4. [SOLVED] VBA code to rearrange data into multiple columns
    By shinobi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2013, 06:33 AM
  5. Rearrange columns
    By Drigomaniac in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-16-2013, 01:02 PM
  6. Rearrange columns because of different dates.
    By Sveinpein in forum Excel General
    Replies: 1
    Last Post: 04-01-2009, 09:46 AM
  7. Rearrange columns using VBA
    By ktpack in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-07-2006, 03:57 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