+ Reply to Thread
Results 1 to 7 of 7

Copy countries from sheet 2 to sheet 3 after certain creteria macro

  1. #1
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Copy countries from sheet 2 to sheet 3 after certain creteria macro

    Hi. I have below test sheet, which have many countries with statistic. The layout is very nice thanks to Alphafrog for some great codes to do that.
    What i need now is the possibility to choose countries to copy the data from sheet 2 to sheet 3.

    The real sheet have many many countries, so it will be a great help.

    I need a macro where a input box ask which countries i need to copy (i guess seperated by comma) press ok
    The next input box shall ask what year. press ok

    The third shall ask which months, would be nice here if i dont fill this one out it just take the upper creteria. All year i have choosen.

    Then it has to copy the country data choosen to sheet 3.(can easily been seen logically in the test sheet)

    If i do again it have to continue with 2 rows blank between the next run of the code.
    This will give me the option to collect date for countries which are connected to each other.

    So i can example collect 4 nordic countries with the year, month etc

    After i can run again with 2 rows seperation example for UK, Ireland.

    All and i think it logically when you check the test sheet how it has to be.

    I have made how it can look in sheet 3. I selected first Argentina and Austria, year 2014 and jan,feb
    After i selected Belgium, Bulgaria ,year 2014 and jan,feb

    And there is 2 blank rows between the 2 runs

    Please have a look, it some which will be a great for me to solve.

    Thanks in advance

    Sincerely

    Abjac
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Copy countries from sheet 2 to sheet 3 after certain creteria macro

    Sorry maybe i asked for too much. But we could start with a code where i could select country and it will copy that country and the belonging data to sheet 3. or maybe with more countries. So if some can help with that would be nice. Is a start and i can work from there then.

    Thanks in advance

    Abjac

  3. #3
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Copy countries from sheet 2 to sheet 3 after certain creteria macro

    Hi.I am trying to find out of how to copy the country and the data for that country but have problems with the off set. Hope some can help with this.

    Thanks in advance

    Sincerely

    Abjac

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,719

    Re: Copy countries from sheet 2 to sheet 3 after certain creteria macro

    Firstly, for this to work effectively, you need to change your sheet design so that the year and country are in two different columns. There are no blank spaces in either of those columns.

    See attached for example and code that will copy and paste to Sheet1 based upon your input. One input at a time.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Copy countries from sheet 2 to sheet 3 after certain creteria macro

    HI alansidman. Thanks for your answer. I understand what you mean by changing the sheets layout.

    I have many countries in the real sheet. Is there a code i can use to change this from what you see to the layout you suggest?

    According to your code it works great. But i need more possibilities.
    To be able to select more than one country, and the complete year for those countries, or select the months for those countries i have chosen.

    I know this is maybe a hard one. But its what i really need.
    Some countries will be connected example Nordic countries.
    Please have a look no rush, but see if this can be done.
    But please start with the code for changing the layout.

    Thanks in advance

    Sincerely

    Abjac

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,719

    Re: Copy countries from sheet 2 to sheet 3 after certain creteria macro

    Here is the first piece of code to clean up your data and put it in a database format.

    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button

  7. #7
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Copy countries from sheet 2 to sheet 3 after certain creteria macro

    HI alansidman. Thanks allot.

    That works like a charm. I tried in the big sheet and it put it perfect in there. So now its in the data format.

    If time could look at the other questions. Would really be great. No rush ok.

    Thanks for now.

    Sincerely

    abjac

+ 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 rows to another sheet after merging using specific creteria
    By saurabh2k26 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2013, 10:37 AM
  2. Replies: 4
    Last Post: 11-20-2012, 05:25 PM
  3. [SOLVED] Macro to Copy Data from one Sheet A to Sheet B based on value in cell on sheet A
    By scass in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2012, 07:21 PM
  4. Macro: Count rows in sheet A, copy count in sheet B, paste offset in sheet A
    By Agent:Orange in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-19-2011, 07:56 AM
  5. Macro/Module running as background process, copy data from sheet to sheet
    By ctor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2009, 05:48 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