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