|
changhuijiang 发表于 2014-2-27 20:31 
求问VBA大神,我的txt文件前面有6行数据不想要,而txt文件数据中有些行第一列数据有的前面有一个空格,这 ...
Sub Macro1()
Dim rng As Range
Workbooks.OpenText Filename:=ThisWorkbook.Path & "\数据例子.txt", Origin:= _
936, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
, 1)), TrailingMinusNumbers:=True
Set txt1 = ActiveWorkbook
r = txt1.Sheets(1).Cells.Find("*", , , , 1, 2).Row
For j = 7 To r
If Len(txt1.Sheets(1).Cells(j, 1)) = 0 Then
If rng Is Nothing Then
Set rng = txt1.Sheets(1).Cells(j, 1)
Else
Set rng = Union(rng, txt1.Sheets(1).Cells(j, 1))
End If
End If
Next j
rng.Delete Shift:=xlToLeft
txt1.Sheets(1).Rows("1:6").Delete Shift:=xlUp
End Sub |
|