+ Reply to Thread
Results 1 to 9 of 9

Move data in several worksheets in same workbook

  1. #1
    Registered User
    Join Date
    02-26-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    40

    Move data in several worksheets in same workbook

    I have a file that we use to show daily sales and orders. The original file had one tab. There is data in columns k through z. Columns M and S contain month to date (MTD) values. Columns L & R show current day sales and is calculated as the delta between today's MTD sales and yesterday's MTD sales.

    The file is linked to another file that contains the current day's MTD sales. Before I update the MTD sales file (and then update the link to said file) I run a macro I built that would move data from columns M and S (current data) to columns B and C (yesterday data). Then I update the link and the "current day" sales are calculated as simple subtraction in columns L & R.

    This worked fine but now we are putting in more tabs to show detail. How do I make reference to each of the new tabs? The column references are the same, I just need to reference each of the individual sheets. My original code was:


    Please Login or Register  to view this content.
    For example we now have tabs called "NorthEast", "West", "SouthEast", etc.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Move data in several worksheets in same workbook

    You need a loop to iterate through the worksheets and then perform the preferred task.

    Please Login or Register  to view this content.
    If there are one or more worksheets which you want excluded, you will need to add some If/Then logic below the For Each line to test for the worksheet name prior to performing the actions (e.g. a summary sheet is often excluded).

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Move data in several worksheets in same workbook

    Something like this perhaps (cleaned up some others). Please test on a copy and report back results. I included an excluded worksheet ("Summary"). If you would like to exclude one, you will need to change to the actual name of the worksheet to be excluded. Otherwise, just comment out that line.

    Please Login or Register  to view this content.
    Without the workbook, it's hard to know if the .Copy / .PasteSpecial is necessary. There is potentially room to skinny the code further via the '.Value = .Value' or '.Copy Destination:=' methods
    Last edited by AlvaroSiza; 05-22-2013 at 03:43 PM.

  4. #4
    Registered User
    Join Date
    02-26-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Move data in several worksheets in same workbook

    I would attach the file but it lists too much sensitive data like customer names etc.

    I tried the code but it says there is a compile error: named argument not found. It highlights the sub in yellow and the Format:= under 'copy and move MTD Orders

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-26-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Move data in several worksheets in same workbook

    Playing around with it a little bit it appears to not like the format specification. I commented it out and the columns moved. Also I guess the .goto range needs to be specific to a particular worksheet?

  6. #6
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Move data in several worksheets in same workbook

    Correct. You will need to specify the sheet name and range that you would like to land when it is finished.

    Example
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-26-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Move data in several worksheets in same workbook

    Ok got it. One last question. What do I put if there are two tabs that I want to exclude from the loop? I tried the following but it does not seem to work.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Move data in several worksheets in same workbook

    Try

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-26-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Move data in several worksheets in same workbook

    "And" worked. Thank you very much for your help. I definitely need to brush up on looping.


    For Each ws In wb.Sheets
    If ws.Name <> "Email Cover" And ws.Name <> "Lookups" Then
    With ws

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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