Consulting

Results 1 to 9 of 9

Thread: Solved: Copy selected filtered sheets to a new workbook

  1. #1
    VBAX Regular
    Joined
    Aug 2011
    Posts
    60
    Location

    Solved: Copy selected filtered sheets to a new workbook

    Hi,
    This is another report that I need to generate. In general I need to copy two sheets over to a new workbook. There are many threads on this topic but not exactly what I want to achieve. I only need the filtered values and selected columns to be copied. I've attached a file to describe what I'm trying to achieve. Makes explanation a lot easier
    Attached Files Attached Files

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    is this file different from the file in your previous thread?


    http://www.vbaexpress.com/forum/showthread.php?t=38699
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Regular
    Joined
    Aug 2011
    Posts
    60
    Location
    Quote Originally Posted by mancubus
    is this file different from the file in your previous thread?


    http://www.vbaexpress.com/forum/showthread.php?t=38699
    Hi mancubus,
    Yeah, it different from that. That file was to copy the filtered range and combine them into a single sheet.

    Where as for this one is to copy the the filtered values only(remove filters, links and codes). Only selected sheets to be copied over to the new workbook.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    see attached...
    check (and change, if necessary, in the code) columns to delete.
    no data in col U!
    Attached Files Attached Files
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    VBAX Regular
    Joined
    Aug 2011
    Posts
    60
    Location
    Quote Originally Posted by mancubus
    see attached...
    check (and change, if necessary, in the code) columns to delete.
    no data in col U!
    Hi mancubus,
    What do you mean by "no data in col U!". Does that mean that I cannot put anything there?

    Oh yeah, about this small remark you put in:
    [VBA]Application.SheetsInNewWorkbook = 3 ' change to suit[/VBA]

    What does that mean

    Apart from that, the code works perfect.

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Quote Originally Posted by aloy78
    Hi mancubus,
    What do you mean by "no data in col U!". Does that mean that I cannot put anything there?

    Oh yeah, about this small remark you put in:
    [vba]Application.SheetsInNewWorkbook = 3 ' change to suit[/vba]

    What does that mean

    Apart from that, the code works perfect.
    hi.

    i mean your data are on columns A thru T.
    sure you can.
    the code provided deletes columns G thru P.
    so if your data table changes, i mean if you add columns etc, you shoud change the line that deletes the columns where necessary.

    [vba]Columns("G:P").Delete[/vba]




    this line makes new blank workbooks open with single worksheet:
    [vba]Application.SheetsInNewWorkbook = 1[/vba]
    this is equal to manually changing the worksheet number:
    options -> general -> include this many sheets: 1


    this line opens blank workbook with single worksheet:
    [vba]Set nwb = Workbooks.Add[/vba]


    this line makes new blank workbooks open with 3 worksheets:
    [vba]Application.SheetsInNewWorkbook = 3 ' change to suit
    [/vba]
    this is equal to manually changing the worksheet number:
    options -> general -> include this many sheets: 3
    you may change the number 3 ifyou like.
    or if your standard is 1 worksheet, then you may delete these two lines other than Workbooks.Add from code.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  7. #7
    VBAX Regular
    Joined
    Aug 2011
    Posts
    60
    Location
    Quote Originally Posted by mancubus
    hi.

    i mean your data are on columns A thru T.
    sure you can.
    the code provided deletes columns G thru P.
    so if your data table changes, i mean if you add columns etc, you shoud change the line that deletes the columns where necessary.

    [vba]Columns("G:P").Delete[/vba]




    this line makes new blank workbooks open with single worksheet:
    [vba]Application.SheetsInNewWorkbook = 1[/vba]
    this is equal to manually changing the worksheet number:
    options -> general -> include this many sheets: 1


    this line opens blank workbook with single worksheet:
    [vba]Set nwb = Workbooks.Add[/vba]


    this line makes new blank workbooks open with 3 worksheets:
    [vba]Application.SheetsInNewWorkbook = 3 ' change to suit
    [/vba]
    this is equal to manually changing the worksheet number:
    options -> general -> include this many sheets: 3
    you may change the number 3 ifyou like.
    or if your standard is 1 worksheet, then you may delete these two lines other than Workbooks.Add from code.
    hi mancubus,
    Thanks for the explanation

    Okay just to summarize. So if I'm gonna export 5 sheets out to that new workbook. Then I will have to amend as below right?
    [vba]
    Application.SheetsInNewWorkbook = 5 ' if I have 5 sheets to copy over to that new workbook
    [/vba]

    Gosh, vba codes are so cool.

  8. #8
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Quote Originally Posted by aloy78
    hi mancubus,
    Thanks for the explanation

    Okay just to summarize. So if I'm gonna export 5 sheets out to that new workbook. Then I will have to amend as below right?
    [vba]
    Application.SheetsInNewWorkbook = 5 ' if I have 5 sheets to copy over to that new workbook
    [/vba]
    Gosh, vba codes are so cool.
    wellcome.

    no.
    it's not related with copying worksheets to another workbook.
    you may copy 100 (or more) worksheets to a blank workbook that contains only 1 blank worksheet.

    i have a standard for my reports or summary reports in excel workbook format: my reports do not contain blank worksheets.
    so I added these lines, by habit , to make your report not contain blank worksheets.

    [vba]
    Application.SheetsInNewWorkbook = 1
    Set nwb = Workbooks.Add
    Application.SheetsInNewWorkbook = 3 ' change to suit
    awb.Activate
    Sheets(Array("Import-Sea", "Import-Air")).Copy Before:=nwb.Sheets(1)
    Application.DisplayAlerts = False
    nwb.Sheets(Sheets.Count).Delete
    Application.DisplayAlerts = True

    [/vba]
    so if you do not care if your report contains blank worksheets, delete the red lines above from macro. remaining lines will be:
    [vba]
    Set nwb = Workbooks.Add
    awb.Activate
    Sheets(Array("Import-Sea", "Import-Air")).Copy Before:=nwb.Sheets(1)
    [/vba]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  9. #9
    VBAX Regular
    Joined
    Aug 2011
    Posts
    60
    Location
    hi mancubus,
    i finally get the picture Yeah I had that same habit of deleting blank sheets in a workbook. And for this, we have solved another vba mystery. hehehe...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •