Sub 另存本表为TXT文件()
Dim i As Integer
Range("d1:d255").Cut Range("b1:b255")
Range("e1:e255").Cut Range("d1:d255")
For i = 1 To 125
If Cells(i * 3, 1) <> "" Then
Cells(i * 3, 6) = UCase(Left(Cells(i * 3, 1), Len(Cells(i * 3, 1)) - 2))
Cells(i * 3, 7) = Round((Cells(i * 3 - 2, 2) + Cells(i * 3 - 1, 2) + Cells(i * 3, 2)) / 3, 3)
Cells(i * 3, 8) = Round((Cells(i * 3 - 2, 3) + Cells(i * 3 - 1, 3) + Cells(i * 3, 3)) / 3, 3)
Cells(i * 3, 9) = Round((Cells(i * 3 - 2, 4) + Cells(i * 3 - 1, 4) + Cells(i * 3, 4)) / 3, 3)
Sheet2.Range("a1:d100").Value = Sheet1.Range("f1:i100").Value
End If
Next
Dim j As Long
For j = Sheet2.Cells(1048576, 2).End(xlUp).Row To 1 Step -1
If Sheet2.Cells(j, 1) = "" Then '如果单元格为空白
Sheet2.Cells(j, 1).EntireRow.Delete '符合条件的都删除整行
End If
Next '检测下一个
Dim s As String
Dim FullName As String, rng As Range
Application.ScreenUpdating = False
FullName = (ActiveSheet.Name & ".txt") '以当前表名为TXT文件名
' FullName = Replace(ThisWorkbook.FullName, ".xls", ".txt") '以当前文件名为TXT文件名
' FullName = Replace(ThisWorkbook.FullName, ".xls", ActiveSheet.Name & ".txt") '以文件名&表名为TXT文件名
Open FullName For Output As #1 '以读写方式打开文件,每次写内容都会覆盖原先的内容
'参考帮助,fullname为文件全名
For Each rng In Sheet2.Range("a1").CurrentRegion
s = s & IIf(s = "", "", ",") & rng.Value
If rng.Column = Sheet2.Range("a1").CurrentRegion.Columns.Count Then
Print #1, s & " " '把数据写到文本文件里
s = ""
' Else
'
' Print #1, s & "" '把数据写到文本文件里
'
' s = ""
End If
Next
Close #1 '关闭文件
Application.ScreenUpdating = True
MsgBox "数据已导入文本"
End Sub