+ Reply to Thread
Results 1 to 11 of 11

Copy across 9 columns of source data into 9 columns of an output table

  1. #1
    Registered User
    Join Date
    01-07-2018
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    39

    Copy across 9 columns of source data into 9 columns of an output table

    I have a spreadsheet with a source tab that has columns of different types of data, each named with a title at the top. I wanted to filter out the columns involving 'fuel cards', of which there are 9 different types (all labelled with 'fuel cards' appearing in the title, but with some slight variation).

    I am looking for some way for this data to copy across to a table with the 9 columns reproduced on a separate tab, with new data added in the table, below the old data.

    The relevant data is in red in the example file. I was hoping to add a new batch of data columns to the source tab each day. This would be added in new columns to the right of the old ones, and mixed among it will be other types of data that I wanted the formula to ignore.

    So the intention is to have the 'fuel cards' tab set up to collect any relevant new data from the inputs tab, and add it to the table, with new rows of data beneath the existing data.

    I was hoping that it might be possible to have a formula in the final table that looks for the correct columns and copies the data across, but which could be changed slightly for each column of the table (to collect the specific column in question). Ideally it could look for the exact text of the column title, and use that to identify the data to copy across.

    My original idea was to use the SMALL function or maybe HLOOKUP to identify the correct columns, but I do not know exactly how to execute it, in terms of getting the data to copy into the table beneath the old data.

    Thank you very much in advance for any help.
    Attached Files Attached Files
    Last edited by nunez100; 01-11-2019 at 12:39 PM.

  2. #2
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: Copy across 9 columns of source data into 9 columns of an output table

    I don't believe Excel can filter out columns, just rows.

    You can do this with a custom view. Just hide the Fuel Card Columns then select Custom Views from the Workbook section of the View tab, select Add, and save the view with a name like "Hide Fuel Card". You may want to save your normal (unhidden Fuel card) view as "Normal" to quickly get back to that.
    Last edited by gjcase; 01-11-2019 at 03:55 PM. Reason: wrong thread by accident

  3. #3
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy across 9 columns of source data into 9 columns of an output table

    If you maintain the current format of your table then this might work. You can assign it to a Form Control button and run it when you complete your monthly entries.
    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  4. #4
    Registered User
    Join Date
    01-07-2018
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    39

    Re: Copy across 9 columns of source data into 9 columns of an output table

    Thank you for your responses.

    Gjcase, I will use your suggestion if I cannot get a formula to work, but I am really hoping that it is possible with a formula.

    JLGWhiz, is your solution VBA code? I am sorry to say that I do not know how to use that, but I could look into it if there is no other way.

    I have been reading some more, and I thought that if it were possible with a formula, then maybe a two way lookup with INDEX and MATCH could be combined with the SMALL function, but I am not certain of how to put it all together.

    I have attached a new version of the example, with just one data set, to make the question as simple as possible. The relevant source data (inputs tab), and the desired output data (Fuel cards tab), are both in red.

    Many thanks again for your responses.
    Attached Files Attached Files

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy across 9 columns of source data into 9 columns of an output table

    Based on how your data is laid out on the Inputs sheet, I think you will need to use VBA to do what you want. It is easy to use. Your security needs to be set to allow access to VBA. This is a one time action. Then the Workbook needs to be saved as a macro enabled (.xlsm) workbook. To install the code, press Alt + F11. If the large pane in the editor window is dark, click 'Insert' on the editor tool bar, then click 'Module'. This is also a one time action. When the large pane brightens, then paste the code into it. You can run the code from the Excel window by pressing Alt + F8, click on the macro name and then click the 'Run' button on the dialog box that popped up. Or, you can assign the macro to a button by going to the Developer tab on the ribbon, click insert under that tab's toll bar which will display both the Form Controls toolbox and the Active-X toolbox. Click on the button in the Form Controls toolbox then move the crosshairs (+) pointer to where you want the button to show on your screen and left click. A dialog box will appear with the option to assign a macro. Click on on 'Assign Macro', Click on the Macro name, Click OK. The button should not activate the macro. Save the file. Now when you need to copy the data, jjust click the button.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Copy across 9 columns of source data into 9 columns of an output table

    You may be able to do this with a Pivot Table.

    Highlight the whole table
    Click Insert/PT/New sheet
    drag Fuel Cards - Registration to "rows"
    drag Fuel Cards - Registration2 to "rows"
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Registered User
    Join Date
    01-07-2018
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    39

    Re: Copy across 9 columns of source data into 9 columns of an output table

    Okay, I have followed your instructions JLGWhiz, and the macro works. Amazing! Thank you very much for this advice!

    I wonder if you noticed the second set of 'fuel cards' data in the inputs tab (also in red)? For some reason the macro seems to only pick up one of the data sets.

    It picks up the one starting in column AE, but not the one starting in column H. Perhaps I am not doing it correctly, but I think I followed all of the instructions.

    Thank you again for this!

    Regards

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy across 9 columns of source data into 9 columns of an output table

    Quote Originally Posted by nunez100 View Post
    Okay, I have followed your instructions JLGWhiz, and the macro works. Amazing! Thank you very much for this advice!

    I wonder if you noticed the second set of 'fuel cards' data in the inputs tab (also in red)? For some reason the macro seems to only pick up one of the data sets.

    It picks up the one starting in column AE, but not the one starting in column H.
    Perhaps I am not doing it correctly, but I think I followed all of the instructions.

    Thank you again for this!

    Regards
    The code provided would only return the last dataset entered. It assumed you had already done the others manually on a monthly basis. I had originally written the code to loop through and return all of the monthly entries, but revised it to only capture the last one so that it would not be adding data to your output report that had already been recorded in the previous month. There was not enough information about how the code would be utilized with respect to the output report in the OP, so I assumed it would be a once a month process with the most recent data being added to the previously recorded data.

  9. #9
    Registered User
    Join Date
    01-07-2018
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    39

    Re: Copy across 9 columns of source data into 9 columns of an output table

    Ah, okay. That makes sense. I guess I would have the option of adding one data set at a time and running the macro each time. However, the really useful thing would be if the macro was able to pick up every data set at once. I should have given more explanation about this in the post. Apologies.

    You mentioned that you had originally written it to collect all entries at once. I wonder if it is possible that you still have this version? It would be perfect if you did. It would be exactly what I needed!

    If not I will have a go with the version you have given me.

    Thank you again, for this help.

  10. #10
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Copy across 9 columns of source data into 9 columns of an output table

    Here is the code that loops the gamut of inputs.
    Please Login or Register  to view this content.
    The problem I see is that you have borders on the cells, which causes big gaps between monthly sets of data. I can probably fix that if you can't work with it. I thought a pastespecial might work, but apparently there is data from the HTML that is interferring. Here is that code, see if it works on an original copy.
    Please Login or Register  to view this content.
    This will definitely get rid of those empty rows.

    Please Login or Register  to view this content.
    Last edited by JLGWhiz; 01-21-2019 at 08:45 PM.

  11. #11
    Registered User
    Join Date
    01-07-2018
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    39

    Re: Copy across 9 columns of source data into 9 columns of an output table

    Hi JLGWhiz,

    Thank you very much for this solution. I have tried it and it does loop around to get several all of the data sets when I add several, so it is perfect.

    I have run out of time on this project for now, so I am not able to apply it fully and check for any glitches, but I think I will mark it as solved for now.

    Thank you very much for solving this problem, I really appreciate your time.

+ 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. Copy columns from source data preserving blank cells
    By nunez100 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-09-2019, 12:12 AM
  2. vba to copy data from source and paste it in output in a specified format
    By Sendilo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2016, 11:12 PM
  3. Replies: 0
    Last Post: 05-16-2014, 04:14 PM
  4. Replies: 3
    Last Post: 03-28-2014, 01:36 PM
  5. Replies: 2
    Last Post: 03-07-2013, 02:16 PM
  6. Looping through columns to copy output into other sheet, and saving output
    By eludlow in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-08-2009, 06:27 AM
  7. Hidden columns in pivot table source data
    By Kaigi in forum Excel General
    Replies: 2
    Last Post: 07-17-2009, 09:34 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