+ Reply to Thread
Results 1 to 3 of 3

To create folders as per worksheet names and create worksheets under them

  1. #1
    Registered User
    Join Date
    03-23-2013
    Location
    slough
    MS-Off Ver
    excel 2007
    Posts
    20

    To create folders as per worksheet names and create worksheets under them

    Hello,

    I have a source file,which has list of all the country reviews about 20 countries.
    They update this file on regular basis. I need to create country files based on the changes and maintain those worksheets.

    The source file is in UPP/TRACKING folder.
    The destination files should be in for example.. for country italy it should be in path..UPP/COUNTRYREVIEWS/ITALY/DECISION AND ACTION LOGS/

    for country greece it should be in UPP/COUNTRYREVIEWS/Greece/DECISION AND ACTION LOGS/

    I have a macro which I have written, which filters the data based on country and creates separate worksheets in the same path as in source file..

    But I need to create the worksheets under different path.. the macro should create folders based on the country or if folders present leave it and copy then under the path specified above..

    This is my macro...


    Sub DistributeRowsToNewWBS()
    Dim wbNew As Workbook
    Dim wsData As Worksheet
    Dim wsCrit As Worksheet
    Dim wsNew As Worksheet
    Dim rngCrit As Range
    Dim LastRow As Long

    Set wsData = Worksheets("overall_reviews1") ' name of worksheet with the data
    Set wsCrit = Worksheets.Add

    LastRow = wsData.Range("B" & Rows.Count).End(xlUp).Row

    ' column H has the criteria
    wsData.Range("E1:E" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsCrit.Range("B1"), Unique:=True

    Set rngCrit = wsCrit.Range("B2")
    While rngCrit.Value <> ""
    Set wsNew = Worksheets.Add
    ' change E to reflect columns to copy
    wsData.Range("B1:R" & LastRow).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=rngCrit.Offset(-1).Resize(2), CopyToRange:=wsNew.Range("B1"), Unique:=True
    wsNew.Name = rngCrit
    wsNew.Copy
    Set wbNew = ActiveWorkbook
    ' saves new workbook in path of existing workbook
    wbNew.SaveAs ThisWorkbook.Path & "\" & rngCrit
    wbNew.Close SaveChanges:=True
    Application.DisplayAlerts = False
    wsNew.Delete
    rngCrit.EntireRow.Delete
    Set rngCrit = wsCrit.Range("B2")
    Wend

    wsCrit.Delete
    Application.DisplayAlerts = True

    End Sub


    Can anybody solve this problem??

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: To create folders as per worksheet names and create worksheets under them

    Hi,

    please always use code tags to paste ur code.
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  3. #3
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: To create folders as per worksheet names and create worksheets under them

    it would be great if u attached the excel sample workbook, its make very much easy to resolve ur query

+ 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