+ Reply to Thread
Results 1 to 2 of 2

VBS Merge Macro with adding feature

Hybrid View

  1. #1
    Registered User
    Join Date
    11-13-2012
    Location
    Italia
    MS-Off Ver
    Excel 2007
    Posts
    11

    VBS Merge Macro with adding feature

    My Macro should merge all xlsx files from a directory and add a column at the end of files merged, with filename where they come from, trunked.

    What's wrong with what I wrote?

    Private Sub CommandButton1_Click()
    Const Path As String = "MyPath"
        
        Dim FileName As String
        Dim WS As Worksheet
        Dim WS2 As Worksheet
        Dim Lastrow As Long
        Dim LastRow2 As Long
        
        Set WS2 = ThisWorkbook.Worksheets(1)
        FileName = Dir(Path & "\*.xlsx", vbNormal)
        Application.ScreenUpdating = False
        Do Until FileName = ""
            If FileName <> ThisWorkbook.Name Then
                Set WS = Workbooks.Open(Path & "\" & FileName).Sheets("Foglio1")
                Lastrow = WS.Cells(500, 1).End(xlUp).Row
                WS.Range("C1").Resize(Lastrow, 7).Copy WS2.Cells(LastRow2 + 1, 1)
                LastRow2 = WS2.Cells(WS2.Rows.Count, 1).End(xlUp).Row
                Cells(Lastrow, LastRow2 + 1).Valure = Left("FileName", 6)
                WS.Parent.Close 0
            End If
            FileName = Dir()
        Loop
        Application.ScreenUpdating = True
    End Sub
    It gives me error in the underlined line..

    Thanks for help

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: VBS Merge Macro with adding feature

    you wrote Cells(Lastrow, LastRow2 + 1).Valure = Left("FileName", 6)
    instead of Cells(Lastrow, LastRow2 + 1).Value = Left("FileName", 6)
    If solved remember to mark Thread as solved

+ 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