6,216
社区成员
发帖
与我相关
我的任务
分享Sub Sort()
Dim sFileName As String
sFileName = "C:\abc.txt"
Dim iFileNum As Integer
iFileNum = FreeFile
Dim data
Dim irow As Integer
irow = 0
Open sFileName For Input As #iFileNum
Cells.Clear
Do Until EOF(iFileNum)
Line Input #iFileNum, data
Cells(1, 1).Offset(irow, 0) = data
irow = irow + 1
Loop
Close #iFileNum
Dim iFinalRow As Integer
iFinalRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row
Dim vArray As Variant
vArray = WorksheetFunction.Transpose(Range("A1:A" & iFinalRow))
Dim i As Integer
For irow = UBound(vArray) To LBound(vArray) Step -1
i = i + 1
Cells(i, 2) = vArray(irow)
Next irow
Open sFileName For Output As #iFileNum
irow = 1
Do
data = Cells(irow, 2)
Print #iFileNum, data
irow = irow + 1
Loop Until IsEmpty(Cells(irow, 1))
Close #iFileNum
End Sub