how to combine only specific files from the list

Summer7sun

New Member
Joined
Sep 14, 2017
Messages
33
I have two folders on my "desktop" : Folder 1 named : "Today" and Folder 2 named : "Destination"
In folder named "Destination" I have multiple files : A.xlsx, B.xlsx, C.xlsx with same headers.
In folder 1 have the latest sale data and I want to combine the latest data with the destination files that is A.xlsx to the A.xlsx from destination folder and b.xlsx to b.xlsx.
I have file named "Master" and have the list of file name from destination From A7:A50
I want to combine the files from the list only. Please help
 
If the file isn't open try
Code:
Set wkbDest = [COLOR=#ff0000]WorkBooks.Open[/COLOR]("C:\Users\Work\Desktop\Destination\" & fName & ".csv")
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
thanks fluff .... pastespecial method of range class failed

Code:
[/COLOR]Sheets(fName.Value).Cells(Sheets(fName.Value).Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial

on this line
 
Upvote 0
Could you post your current code, as that line isn't in the last code you posted.
 
Upvote 0
Fluff i messed up with the codes ... and previous person who was helping me out said to have a new thread coz he dint have expertise on it... any ways.... all these time was tryin out with the codes ....

Code:
Dim fName As Range
     
    Dim Master As Worksheet
    Set Master = ThisWorkbook.Sheets("Master")
    Dim wkbDest As Workbook
    Dim wkbSource As Workbook
    
    For Each fName In Master.Range("A7:A50")
   
        Set wkbSource = Workbooks.Open(CreateObject("WScript.Shell").specialfolders("Desktop") & "\Today\" & fName & ".csv")
        Sheets(fName.Value).Range("A2", Sheets(fName.Value).Cells.SpecialCells(xlCellTypeLastCell)).Copy
        wkbSource.Close False
        
        Set wkbDest = Workbooks.Open(CreateObject("WScript.Shell").specialfolders("Desktop") & "\Destination\" & fName & ".csv")
        Sheets(fName.Value).Cells(Sheets(fName.Value).Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
        wkbDest.Close True
        
        Next fName


I got the code to work however the code returns an error saying .csv not found , I suppose that the range is a7:a50 and m using only two files so as a9 to a50 are blank i believe for that it returns this error .... I want it to do until range = "" however cant get it to work.
 
Last edited:
Upvote 0
In that case try
Code:
For Each fname In Range("A7:A50").SpecialCells(xlConstants)
 
Upvote 0
Fluff ... Facing some issue
If i place a file which has huge data in the Today folder "by huge i mean data from a1 z6000 .. I get the clipboard error and after clicking no get this error run time error 1004 pastespecial method of range class failed

on this line

Code:
Sheets(fName.Value).Cells(Sheets(fName.Value).Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial


how ever if i run the code with less data it works
 
Last edited:
Upvote 0
Either click Yes rather than no, or try this
Code:
Application.DisplayAlerts = False
   For Each fname In Master.Range("A7:A50")
   
      Set wkbSource = Workbooks.Open(CreateObject("WScript.Shell").specialfolders("Desktop") & "\Today\" & fname & ".csv")
      Sheets(fname.Value).Range("A2", Sheets(fname.Value).Cells.SpecialCells(xlCellTypeLastCell)).Copy
      wkbSource.Close False
      
      Set wkbDest = Workbooks.Open(CreateObject("WScript.Shell").specialfolders("Desktop") & "\Destination\" & fname & ".csv")
      Sheets(fname.Value).Cells(Sheets(fname.Value).Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
      wkbDest.Close True
   
   Next fname
Application.DisplayAlerts = True
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top