+ Reply to Thread
Results 1 to 12 of 12

Delete row if cell J contains any text

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    37

    Delete row if cell J contains any text

    Hello,

    I am trying to write a program to delete a row if column J contains any sort of text. The text in column J is not the same. Any help is appreciated!

    TIA
    Last edited by tactical; 05-30-2012 at 03:24 PM.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Delete row if cell J contains any text

    *Untested*

    Please make a copy of your workbook and test on the copy. If you are unfamiliar with how to run the code, please use the instructions in my signature.

    Sub DeleteRow()
    
    Dim rngSearch As Range
    Dim rngCell As Range
    
    'You will need to change the sheet name if different from "Sheet1"
    Set rngSearch = ActiveWorkbook.Sheets("Sheet1").Range("J1", Range("J1").End(xlDown))
    
       For Each rngCell In rngSearch
          If Application.WorksheetFunction.IsText(Range(rngCell)) Then
             rngCell.EntireRow.Delete
          End If
       Next rngCell
    
    End Sub
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Delete row if cell J contains any text

    I have used this one.

    Sub wis_niet_lege_rijen_oeldere()
        Columns(11).SpecialCells(2).EntireRow.Delete             'cells contains text
     
        Columns(11).SpecialCells(-4123).EntireRow.Delete         'cells contains formula
      
      If Err.Number <> 0 Then MsgBox "There are no empty cells"
      
     End Sub
    Columns(11) = "J"
    Last edited by oeldere; 05-30-2012 at 04:44 PM. Reason: changed text used

  4. #4
    Registered User
    Join Date
    05-31-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Delete row if cell J contains any text

    Quote Originally Posted by oeldere View Post
    I have used this one.

    Sub wis_niet_lege_rijen_oeldere()
        Columns(11).SpecialCells(2).EntireRow.Delete             'cells contains text
     
        Columns(11).SpecialCells(-4123).EntireRow.Delete         'cells contains formula
      
      If Err.Number <> 0 Then MsgBox "There are no empty cells"
      
     End Sub
    Columns(11) = "J"
    J is actually column 10. I am getting Delete method of Range class failed error for this one

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Delete row if cell J contains any text

    J is actually column 10
    you are right => J= colomn 10

    I send you my example.

    first run macro

    Sub delete_NOT_empty_row_in_columnC_oeldere()

    then run

    Sub delete_empty_row_in_columnA()

    This one works fine for me.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-31-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Delete row if cell J contains any text

    Quote Originally Posted by oeldere View Post
    J is actually column 10
    you are right => J= colomn 10

    I send you my example.

    first run macro

    Sub delete_NOT_empty_row_in_columnC_oeldere()

    then run

    Sub delete_empty_row_in_columnA()

    This one works fine for me.
    Yours is working, but mine is not.

  7. #7
    Registered User
    Join Date
    05-31-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Delete row if cell J contains any text

    Quote Originally Posted by AlvaroSiza View Post
    *Untested*

    Please make a copy of your workbook and test on the copy. If you are unfamiliar with how to run the code, please use the instructions in my signature.

    Sub DeleteRow()
    
    Dim rngSearch As Range
    Dim rngCell As Range
    
    'You will need to change the sheet name if different from "Sheet1"
    Set rngSearch = ActiveWorkbook.Sheets("Sheet1").Range("J1", Range("J1").End(xlDown))
    
       For Each rngCell In rngSearch
          If Application.WorksheetFunction.IsText(Range(rngCell)) Then
             rngCell.EntireRow.Delete
          End If
       Next rngCell
    
    End Sub
    Im getting a on Method 'Range' of object '_Global' failed error with this code.

    I don't think it like the "If Application.WorksheetFunction.IsText(Range(rngCell)) Then" line
    Last edited by tactical; 05-30-2012 at 04:54 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    863

    Re: Delete row if cell J contains any text

    Sub hsv()
    Dim i As Long
    Application.ScreenUpdating = False
     For i = Cells(Rows.Count, 1).End(xlUp).Row To 3 Step -1
      If Cells(i, 10) = "" Then Cells(i, 10).EntireRow.Delete
     Next i
    End Sub
    Harry.

  9. #9
    Registered User
    Join Date
    05-31-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Delete row if cell J contains any text

    Quote Originally Posted by HSV View Post
    Sub hsv()
    Dim i As Long
    Application.ScreenUpdating = False
     For i = Cells(Rows.Count, 1).End(xlUp).Row To 3 Step -1
      If Cells(i, 10) = "" Then Cells(i, 10).EntireRow.Delete
     Next i
    End Sub
    This deletes the empty rows. What do I need instead of "" to make it delete rows that contain any string?

  10. #10
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    863

    Re: Delete row if cell J contains any text

    Use:

    <> ""

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1