+ Reply to Thread
Results 1 to 20 of 20

Automatically make new excel-files (and save in specific folder on my computer)

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2014
    Location
    Assen, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Automatically make new excel-files (and save in specific folder on my computer)

    Example data.xlsxCan someone help me with a good VBA-code for underlying problem?

    I have to save a lot of excel-files with different names. (about 100)
    I need a macro to automatically save excel-files with different names in a specific folder on my computer.

    See attachment.

    The name of the files should contain the combination of column G and H. (for example "1206 - Praktijkhuisman.xlsx")
    He should make a new file when there is an other unique value in Column G.


    After making a new excelfile he should copy the data (include layout) in a tab (with same name as the new excel file) from column A t/m L.
    Only the data for the Unique value in Column G.

    Please can someone help me??
    Attached Images Attached Images
    Last edited by Josvanderwaaij; 08-20-2014 at 06:03 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Hi..

    Attaching an image might help you if this was a photoshop forum..

    Best to attach an excel file showing raw data and desired result.

  4. #4
    Registered User
    Join Date
    08-20-2014
    Location
    Assen, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Thanks for your advice.

    I attached a file with raw data.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Maybe:

    Sub Josvanderwaaij()
    Dim wbkTest As Worksheet
    Dim i As Long
    Dim x As String
    Dim wbk As Workbook
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Set wbkTest = ActiveSheet
    For i = 2 To Range("G" & Rows.count).End(3).Row
    x = wbkTest.Range("G" & i).Value & " - " & wbkTest.Range("H" & i).Value & ".xls"
    On Error Resume Next
    Workbooks.Add
    ActiveWorkbook.SaveAs x
    Sheets("Sheet1").Rows(1).Value = wbkTest.Rows(1).Value
    On Error GoTo 0
    wbkTest.Activate
    Next i
    For Each wbk In Workbooks
        If Left(wbk.Name, 4) = "Book" Then wbk.Close
    Next wbk
    wbkTest.Activate
    For i = 2 To Range("G" & Rows.count).End(3).Row
    x = wbkTest.Range("G" & i).Value & " - " & wbkTest.Range("H" & i).Value & ".xls"
    If Left(wbkTest.Range("G" & i).Value, 3) = Left(Workbooks(x).Name, 3) Then
        wbkTest.Rows(i).Copy Workbooks(x).Sheets("Sheet1").Range("A" & Rows.count).End(3)(2)
    End If
    wbkTest.Activate
    Next i
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

  6. #6
    Registered User
    Join Date
    08-20-2014
    Location
    Assen, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Thanks so far.

    Couple of problems.

    1. add new workbooks with names is working correctly
    - only he makes also a lot of new maps without a name and didn't close those new maps.

    2. He didn't name the sheet the same as the workbook and he didn't copy the values in the sheet.

    Can you help me? I still have to learn a lot about VBA.

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Try:

    Sub Josvanderwaaij()
    Dim wbkTest As Worksheet
    Dim i As Long
    Dim x As String
    Dim wbk As Workbook
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Set wbkTest = ActiveSheet
    For i = 2 To Range("G" & Rows.count).End(3).Row
    x = wbkTest.Range("G" & i).Value & " - " & wbkTest.Range("H" & i).Value & ".xlsx"
    On Error Resume Next
    Workbooks.Add
    ActiveWorkbook.SaveAs x
    Sheets("Sheet1").Rows(1).Value = wbkTest.Rows(1).Value
    Sheets("Sheet1").Name = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5)
    On Error GoTo 0
    wbkTest.Activate
    Next i
    For Each wbk In Workbooks
        If Left(wbk.Name, 4) = "Book" Then wbk.Close
    Next wbk
    wbkTest.Activate
    For i = 2 To Range("G" & Rows.count).End(3).Row
    x = wbkTest.Range("G" & i).Value & " - " & wbkTest.Range("H" & i).Value & ".xlsx"
    If Left(wbkTest.Range("G" & i).Value, 3) = Left(Workbooks(x).Name, 3) Then
        wbkTest.Rows(i).Copy Workbooks(x).Sheets(Left(Workbooks(x).Name, Len(Workbooks(x).Name) - 5)).Range("A" & Rows.count).End(3)(2)
    End If
    wbkTest.Activate
    Next i
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

  8. #8
    Registered User
    Join Date
    08-20-2014
    Location
    Assen, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Knipsel.JPG
    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe:

    Sub Josvanderwaaij()
    Dim wbkTest As Worksheet
    Dim i As Long
    Dim x As String
    Dim wbk As Workbook
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Set wbkTest = ActiveSheet
    For i = 2 To Range("G" & Rows.count).End(3).Row
    x = wbkTest.Range("G" & i).Value & " - " & wbkTest.Range("H" & i).Value & ".xls"
    On Error Resume Next
    Workbooks.Add
    ActiveWorkbook.SaveAs x
    Sheets("Sheet1").Rows(1).Value = wbkTest.Rows(1).Value
    On Error GoTo 0
    wbkTest.Activate
    Next i
    For Each wbk In Workbooks
        If Left(wbk.Name, 4) = "Book" Then wbk.Close
    Next wbk
    wbkTest.Activate
    For i = 2 To Range("G" & Rows.count).End(3).Row
    x = wbkTest.Range("G" & i).Value & " - " & wbkTest.Range("H" & i).Value & ".xls"
    If Left(wbkTest.Range("G" & i).Value, 3) = Left(Workbooks(x).Name, 3) Then
        wbkTest.Rows(i).Copy Workbooks(x).Sheets("Sheet1").Range("A" & Rows.count).End(3)(2)
    End If
    wbkTest.Activate
    Next i
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub
    I get also message with this error (see attachement)
    Fould 9 - Subscript is out of range

  9. #9
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Hi..

    Only the data for the Unique value in Column G.
    So.. as an example.. would that mean that the first file would be called '1206 - Praktijkhuisman.xlsx' and it should have a sheet called the same name and on that sheet would be the data from A2:L5?

    And second file would be called '205 - De Hoeksteen.xlsx'. having a sheet in it called the same and data would be from A6:L6?

  10. #10
    Registered User
    Join Date
    08-20-2014
    Location
    Assen, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Yes, that is correct! It would save me a lot of time.

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Automatically make new excel-files (and save in specific folder on my computer)

    Based on the posts try this on the Dutch version. Although trial and error may not be the best way to decipher a different language.

    Sub Josvanderwaaij()
    Dim wbkTest As Worksheet
    Dim i As Long
    Dim x As String
    Dim wbk As Workbook
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Set wbkTest = ActiveSheet
    For i = 2 To Range("G" & Rows.count).End(3).Row
    x = wbkTest.Range("G" & i).Value & " - " & wbkTest.Range("H" & i).Value & ".xlsx"
    On Error Resume Next
    Workbooks.Add
    ActiveWorkbook.SaveAs x
    Sheets("Sheet1").Rows(1).Value = wbkTest.Rows(1).Value
    Sheets("Sheet1").Name = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5)
    On Error GoTo 0
    wbkTest.Activate
    Next i
    For Each wbk In Workbooks
        If Left(wbk.Name, 3) = "Map" Then wbk.Close
    Next wbk
    wbkTest.Activate
    For i = 2 To Range("G" & Rows.count).End(3).Row
    x = wbkTest.Range("G" & i).Value & " - " & wbkTest.Range("H" & i).Value & ".xlsx"
    If Left(wbkTest.Range("G" & i).Value, 3) = Left(Workbooks(x).Name, 3) Then
        wbkTest.Rows(i).Copy Workbooks(x).Sheets(Left(Workbooks(x).Name, Len(Workbooks(x).Name) - 5)).Range("A" & Rows.count).End(3)(2)
    End If
    wbkTest.Activate
    Next i
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

+ 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: 01-28-2019, 06:55 PM
  2. one folder & so many excel files are save, i want name change without open excel files
    By sonu_kumar444 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2013, 03:45 PM
  3. Replies: 1
    Last Post: 01-24-2006, 11:35 AM
  4. Replies: 1
    Last Post: 01-24-2006, 11:00 AM
  5. Replies: 1
    Last Post: 01-24-2006, 12:25 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