Posted to microsoft.public.excel.programming
|
|
Help with macro. Import text file (fixed width)
On Mar 25, 1:06*am, Dick Kusleika wrote:
On Mon, 24 Mar 2008 11:34:03 -0700 (PDT), Sinner wrote:
Things I want to add a
- Simple button in sheet to start macro
Show the Forms toolbar. *Drag a commandbutton onto your sheet. *Assign
Macro1.
- Ask for text file destination folder
http://www.dailydoseofexcel.com/arch...topenfilename/
- Delete first 8 rows
Change your StartRow argument to StartRow:=9
- Delete row with 4 or more character '----'
- Delete row with word containing total
- Delete row with 4 or more character '===='
- All data asending order with respect to columnC (entire data & not
just columnC).
Untested, but should work
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 24/03/2008 by
'
'
* * Dim wb As Workbook
* * Dim ws As Worksheet
* * Dim rng As Range
* * Dim i As Long
* * Const sDASH As String = "----"
* * Const sEQUAL As String = "===="
* * Const sTOTAL As String = "Total"
* * Set wb = Workbooks.OpenText(Filename:= _
* * * * "C:\Documents and Settings\rambo\Desktop\ST ReCON\STS 24.TXT",
Origin:= _
* * * * 437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0,
1), _
* * * * Array(30, 2), Array(42, 1), Array(56, 1), Array(90, 1), Array(140,
1)), _
* * * * TrailingMinusNumbers:=True)
* * Set ws = wb.Sheets(1)
* * Set rng = Intersect(ws.Columns(1), ws.UsedRange)
* * For i = rng.Cells(rng.Cells.Count).Row To 1 Step -1
* * * * If InStr(1, rng.Cells(i).Value, sDASH) 0 Or _
* * * * * * InStr(1, rng.Cells(i).Value, sEQUAL) 0 Or _
* * * * * * InStr(1, rng.Cells(i).Value, sTOTAL) 0 Then
* * * * * * rng.Cells(i).EntireRow.Delete
* * * * End If
* * Next i
* * ws.UsedRange.Sort ws.Range("C1"), xlAscending, , , , , , xlNo
* * ws.UsedRange.Columns.AutoFit
* * ActiveWindow.Zoom = 85
End Sub
--
Dick Kusleika
Microsoft MVP-Excelhttp://www.dailydoseofexcel.com
Dear Kusleika,
It says Compile error: Expected Function or variable.
|