Sorry about the urgent bit - only just seen this thread but I reckon this is what you're after!
VB Code:
Private Const strFilePathAndName As String = "C:\File.txt" Private Sub CommandButton1_Click() Dim intLoopCounter As Integer Dim strFile4thLinesText As String ' Open up the above specified file for reading Open strFilePathAndName For Input As #1 ' Loop through each line of text in the file - the current ' line number is kept in the intLoopCounter variable. When the ' fourth line of text is hit, the line of text is stored in the ' strFile4thLinesText string variable & the loop is exited. Do While Not EOF(1) intLoopCounter = intLoopCounter + 1 Line Input #1, strFile4thLinesText strFile4thLinesText = CStr(Trim(strFile4thLinesText)) If (intLoopCounter = 4) Then Exit Do End If Loop Close #1 ' Loop through each used row in the first worksheet, note this starts at the ' first row / row 1 so if you've got a title row you'll want to alter this! Sheets("Sheet1").Activate For intLoopCounter = 1 To UsedRange.Rows.Count ' If either the value in the 5th or 6th column of the current row is greater ' than the one from the 4th line of the text file, delete the row. If CInt(Cells(intLoopCounter, 5).Value) > CInt(strFile4thLinesText) Or _ CInt(Cells(intLoopCounter, 6).Value) > CInt(strFile4thLinesText) Then Cells(intLoopCounter, 5).Select ActiveCell.EntireRow.Delete shift:=xlShiftUp intLoopCounter = intLoopCounter - 1 End If Next intLoopCounter End Sub





Reply With Quote