vanthinh3101
Thành viên tích cực


- Tham gia
- 24/1/15
- Bài viết
- 1,118
- Được thích
- 1,452
- Giới tính
- Nam
- Nghề nghiệp
- Finance
Code cho bạn:Dear bạn
cảm ơn b , tớ giải quyết được vấn đề cho sheet IN rồi
Tuy nhiên còn sheet OUt tớ ko hiểu lắm , bạn giải thích giúp t được ko ?
Đồng thời , với file text xuất , định dạng các cột trong file ko giống so với file text IN , nên theo tớ nghĩ code cho OUT sẽ khác chứ bạn ?
thank for support
PHP:
Public Sub ImportTxt_ToExcel_sheetOut()
Dim Fso As Object, TextSource As Object, TotalLines, Item, Tmp
Dim K As Long, I As Long, J As Long, sArr(1 To 500000, 1 To 4), lR As Long
Set Fso = CreateObject("Scripting.FileSystemObject")
Application.ScreenUpdating = False
MsgBox "Chon File TXT Import" & Chr(10) & "(Co the chon Nhieu File de Import)"
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Filters.Add "TXT File", "*.txt", 1
If Not .Show = -1 Then
MsgBox "Ban chua chon File", vbInformation, "----Mr.GPE----"
Exit Sub
End If
On Error Resume Next
For Each Item In .SelectedItems
Set TextSource = Fso.OpenTextFile(Item, 1, , -2)
TotalLines = Split(TextSource.ReadAll, vbCrLf)
For I = 0 To UBound(TotalLines)
If Len(TotalLines(I)) Then
Tmp = Split(TotalLines(I), ",")
K = K + 1: sArr(K, 1) = Tmp(7)
sArr(K, 2) = Tmp(3): sArr(K, 4) = Right(sArr(K, 1), 3)
sArr(K, 3) = DateSerial(Left(Tmp(0), 4), Mid(Tmp(0), 5, 2), Right(Tmp(0), 2))
End If
Next
Next
End With
If K Then
lR = Sheet31.Range("A" & Rows.Count).End(xlUp).Row + 1
Sheet31.Range("A" & lR).Resize(K, 4).Value = sArr
End If
MsgBox "Done!"
Application.ScreenUpdating = True
End Sub