|
-
Apr 22nd, 2003, 10:03 PM
#1
Thread Starter
Lively Member
cHECKING COLUMNS IN EXCEL..?hELP!!uRGENT
I need to check the 4th line in a text file named parameters.txt. It will b either 0,1,2,3,4,5,6,7 or 8.I have 6 columns of data in Excel.Column A, B,C,D,E,F. I want to check thru the 4th and 5th columns(D,E). If any of the values is more than the num in the text file, I want the WHOLE ROW of data to be deleted and the next row of data to be shifted up in the Sheet.Hope u understand what I mean.Can anyone pls help.? Its urgent.I dunno how to do it.Thanks
-
Apr 24th, 2003, 09:50 AM
#2
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|