Hello agin All, I stumbled across some code and thought I could modify and use it in my application. But I don't seem to be able to get it to work. I want to be able to have this program open up a text file the user picks and sort out any "blank" rows and any rows that do not have, in this case the "AFF" in the row and delete them as well. I can get it to display the open dialog box and open the file and copy it to a template. But when the RemoveGarbageTowers runs it deletes everything. Can somebody help me find the problem and maybe tell me what the "ElseIf .Cells(Row, 3) <> "AFF" Then" means? What does the (Row, 3) signify? I have had success with a very similar set of code for a excel spreadsheet. Is it the .txt that is the problem? Or could it have something to do with the field info Array instructions. They were there and I didn't think it would be a problem because the file comes in OK from the OpenDataFiles routine.
thanks for any help or insight you can offer
Walt
Sub OpenDataFiles()
Dim Datafile As Variant
Datafile = Application.GetOpenFilename(Title:="Please find and open the Towers file now")
If Datafile = False Then
MsgBox "Please provide the location of the datafile"
Datafile = Application.GetOpenFilename(Title:="Please find and open the Towers file now")
If Datafile = False Then
Exit Sub
End If
End If
' Opens the data file and imports just the relevant columns
Workbooks.OpenText FileName:=Datafile, _
Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), _
Array(10, 9), Array(22, 1), Array(52, 9), Array(63, 1), Array(67, 9), Array(68, 1), _
Array(74, 9), Array(75, 1), Array(80, 9), Array(81, 1), Array(87, 9), Array(105, 1), _
Array(135, 1), Array(161, 1))
ActiveSheet.Select
ActiveSheet.Copy
ActiveSheet.Move Before:=ThisWorkbook.Sheets(2)
RemoveGarbageTowers
End Sub
Sub RemoveGarbageTowers()
Dim Row As Long
Dim Bot As Long
Bot = GetBottomRowOfColumn(Sheetname, 3)
With ActiveSheet
For Row = Bot To 1 Step -1
If .Cells(Row, 3).Value = "" Then
.Rows(Row).Delete
ElseIf .Cells(Row, 3) <> "AFF" Then
.Rows(Row).Delete
Row = Row + 1
End If
Next
End With
End Sub
thanks for any help or insight you can offer
Walt
Sub OpenDataFiles()
Dim Datafile As Variant
Datafile = Application.GetOpenFilename(Title:="Please find and open the Towers file now")
If Datafile = False Then
MsgBox "Please provide the location of the datafile"
Datafile = Application.GetOpenFilename(Title:="Please find and open the Towers file now")
If Datafile = False Then
Exit Sub
End If
End If
' Opens the data file and imports just the relevant columns
Workbooks.OpenText FileName:=Datafile, _
Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), _
Array(10, 9), Array(22, 1), Array(52, 9), Array(63, 1), Array(67, 9), Array(68, 1), _
Array(74, 9), Array(75, 1), Array(80, 9), Array(81, 1), Array(87, 9), Array(105, 1), _
Array(135, 1), Array(161, 1))
ActiveSheet.Select
ActiveSheet.Copy
ActiveSheet.Move Before:=ThisWorkbook.Sheets(2)
RemoveGarbageTowers
End Sub
Sub RemoveGarbageTowers()
Dim Row As Long
Dim Bot As Long
Bot = GetBottomRowOfColumn(Sheetname, 3)
With ActiveSheet
For Row = Bot To 1 Step -1
If .Cells(Row, 3).Value = "" Then
.Rows(Row).Delete
ElseIf .Cells(Row, 3) <> "AFF" Then
.Rows(Row).Delete
Row = Row + 1
End If
Next
End With
End Sub