+ Reply to Thread
Results 1 to 10 of 10

Alternative to copy and paste values based on criteria

  1. #1
    Registered User
    Join Date
    04-27-2015
    Location
    Manchester
    MS-Off Ver
    microsoft 2007
    Posts
    9

    Alternative to copy and paste values based on criteria

    Hi,

    So i have a sheet with various bits of data on it and need to populate new tabs according to a specific field. Although this is not my file, in the attached as an example i would look to populate new tabs f-or each unique state. So a tab for LA, MI, NJ etc. Now at the momement i create a pivot and use a for loop to create a new sheet per state. I would then use range of new sheet = us-500's range and then delete all rows where the data doesn't match the current sheet name. The issue is that this is a lengthy task if there are 1000s of rows to delete. Does anyone have an alternative?
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Alternative to copy and paste values based on criteria

    Hi krishns

    Why not Filter for each unique State then copy the Filtered Data to a new worksheet?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    04-27-2015
    Location
    Manchester
    MS-Off Ver
    microsoft 2007
    Posts
    9

    Re: Alternative to copy and paste values based on criteria

    Hi,

    I'm looking to completely automate a process using cost codes rather than state. The issue is that there may be new cost codes added to the data so filtering will only work for the initially used cost codes.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Alternative to copy and paste values based on criteria

    Hi krishns

    Create a Dynamic Named Range of Unique Cost Codes...call it CostCodes. This can be done with Code. As new Cost Codes are added they'll be added to the Dynamic Named Range.

    See this Link...

    http://www.ozgrid.com/Excel/DynamicRanges.htm

  5. #5
    Registered User
    Join Date
    04-27-2015
    Location
    Manchester
    MS-Off Ver
    microsoft 2007
    Posts
    9

    Re: Alternative to copy and paste values based on criteria

    Quote Originally Posted by jaslake View Post
    Hi krishns

    Create a Dynamic Named Range of Unique Cost Codes...call it CostCodes. This can be done with Code. As new Cost Codes are added they'll be added to the Dynamic Named Range.

    See this Link...

    http://www.ozgrid.com/Excel/DynamicRanges.htm
    Hi,

    Thanks for your reply.

    My preference where possible is not to copy and paste as with large data sets excel seems to struggle. I can potentially be using over 30000 lines and in the past with a previous macro i created excel would struggle/crash when attempting to copy and paste

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Alternative to copy and paste values based on criteria

    Hi krishns

    I believe Auto Filter, Copy, Paste is the most expedient approach. Formulas, with that much Data, will "kill" Excel.

    I'll be glad to look at it but I'll need a Sample of your actual Data. The File you attached is not representative of your actual Data.

  7. #7
    Registered User
    Join Date
    04-27-2015
    Location
    Manchester
    MS-Off Ver
    microsoft 2007
    Posts
    9

    Re: Alternative to copy and paste values based on criteria

    Hi,

    I feel i'm almost there with a solution, please see macro "Issues". Rather than making all values in the selection = to range it only matches the table headers
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Alternative to copy and paste values based on criteria

    Hi,
    I looked at your macro "Issues", but could not understand what information you where trying to convey.

    I think you may not fully understand the implication of using Range.SpecialCells(xlCellTypeVisible). When used, the Range may (probably will) contain multiple areas that you need to iterate through. Here is example based on your spreadsheet. I probably have not set it up completely the way you would like it, but it should give you an idea of the steps needed.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-27-2015
    Location
    Manchester
    MS-Off Ver
    microsoft 2007
    Posts
    9

    Re: Alternative to copy and paste values based on criteria

    Quote Originally Posted by TnTinMN View Post
    Hi,
    I looked at your macro "Issues", but could not understand what information you where trying to convey.

    I think you may not fully understand the implication of using Range.SpecialCells(xlCellTypeVisible). When used, the Range may (probably will) contain multiple areas that you need to iterate through. Here is example based on your spreadsheet. I probably have not set it up completely the way you would like it, but it should give you an idea of the steps needed.

    Please Login or Register  to view this content.
    Hi TnTinMN,

    Thans, this works really well. Please can you modify the code to also incorporate table headers?

  10. #10
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Alternative to copy and paste values based on criteria

    Quote Originally Posted by krishns View Post
    Hi TnTinMN,

    Thans, this works really well. Please can you modify the code to also incorporate table headers?
    I could, but what is preventing you from doing it yourself?

    I feel that the code has sufficient comments on the exclusion of the header that you should be able to figure out what needs to be modified.

    If your do not understand what a particular command does, do you look it up in Excel's VBA Help. You can place the cursor on the commands you do not understand and press the "F1" key to bring up the built-in help.

    Give it try yourself.

+ 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. Replies: 1
    Last Post: 10-05-2014, 12:28 PM
  2. [SOLVED] copy Tabs, based on two criteria in column J and paste values
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-13-2013, 03:46 PM
  3. [SOLVED] Macro to Copy Data and Paste Values Based on cell criteria
    By Taislin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-16-2012, 06:51 PM
  4. copy and paste values based on a criteria
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 11-15-2008, 11:35 AM
  5. [SOLVED] Alternative to Copy and paste values in VBA
    By thisguy in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-12-2005, 12:05 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