Results 1 to 2 of 2

Thread: cHECKING COLUMNS IN EXCEL..?hELP!!uRGENT

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86

    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

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Sorry about the urgent bit - only just seen this thread but I reckon this is what you're after!
    VB Code:
    1. Private Const strFilePathAndName As String = "C:\File.txt"
    2.  
    3. Private Sub CommandButton1_Click()
    4.     Dim intLoopCounter As Integer
    5.     Dim strFile4thLinesText As String
    6.    
    7.     ' Open up the above specified file for reading
    8.     Open strFilePathAndName For Input As #1
    9.    
    10.         ' Loop through each line of text in the file - the current
    11.         ' line number is kept in the intLoopCounter variable. When the
    12.         ' fourth line of text is hit, the line of text is stored in the
    13.         ' strFile4thLinesText string variable & the loop is exited.
    14.         Do While Not EOF(1)
    15.             intLoopCounter = intLoopCounter + 1
    16.             Line Input #1, strFile4thLinesText
    17.             strFile4thLinesText = CStr(Trim(strFile4thLinesText))
    18.            
    19.             If (intLoopCounter = 4) Then
    20.                 Exit Do
    21.             End If
    22.         Loop
    23.    
    24.     Close #1
    25.  
    26.     ' Loop through each used row in the first worksheet, note this starts at the
    27.     ' first row / row 1 so if you've got a title row you'll want to alter this!
    28.     Sheets("Sheet1").Activate
    29.    
    30.     For intLoopCounter = 1 To UsedRange.Rows.Count
    31.        
    32.         ' If either the value in the 5th or 6th column of the current row is greater
    33.         ' than the one from the 4th line of the text file, delete the row.
    34.         If CInt(Cells(intLoopCounter, 5).Value) > CInt(strFile4thLinesText) Or _
    35.         CInt(Cells(intLoopCounter, 6).Value) > CInt(strFile4thLinesText) Then
    36.             Cells(intLoopCounter, 5).Select
    37.             ActiveCell.EntireRow.Delete shift:=xlShiftUp
    38.            
    39.             intLoopCounter = intLoopCounter - 1
    40.         End If
    41.        
    42.     Next intLoopCounter
    43. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width