Consolidate multiple file in designated folder (Invalid code for long figues)

alexxgalaxy

New Member
Joined
Sep 19, 2011
Messages
2
I used the following code to consolidate the data in multiple files in a designated folder. The codes work perfect when the source files are excel but there is issue with csv/txt file. When it is csv/txt file, if value of the cell is some figures with many digits, the copied value changes in worksheet to where all the copied data is pasted. In my case, for example, the original value of the cell is 788505632017 but it eneded up 788506000000 in destination file. I tried to change the format of the cell to Text before running the macros but in vain. Can anybody help with this? Thanks so much in advance!


Code:
Sub GatherData()
    On Error Resume Next
   
    
    Dim sPath As String
    Dim Wb As Workbook
    Dim sFile As String
 
    
    sPath = "J:\temp\"
     
    sFile = Dir(sPath & "*.csv")
    
    Application.ScreenUpdating = False
    
        Do While sFile <> ""
        
        Set Wb = Workbooks.Open(sPath & sFile)
        Sheets(1).Activate
        
        ActiveSheet.UsedRange.Copy
        
        Application.DisplayAlerts = False
          
        Wb.Close SaveChanges:=False
        
        Application.DisplayAlerts = True
        
        Range("A" & Rows.Count).End(xlUp).Offset(2, 0).PasteSpecial Paste:=xlPasteAll
        
      Application.CutCopyMode = False
      
        
    sFile = Dir
        
    Loop
 
   Application.ScreenUpdating = True
   
 End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,214,788
Messages
6,121,597
Members
449,038
Latest member
Arbind kumar

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