Consulting

Results 1 to 5 of 5

Thread: Delete the row if cell contains null value else as it is ?

  1. #1

    Delete the row if cell contains null value else as it is ?

    Dear All,

    Greetings of the day!!!!!
    In my excel workbook a column consist the following records.
    i.e In Col I record in each individual cell is pipe,flange, valve reducer, tee, ELL.
    Sample is for ref.
    if the cell contains in I is pipe,flange, valve reducer, tee,or ELL then leave that row as it is
    else delete the row.
    The search start from beggining to end.
    Attachment is for reference.
    Is there any macro to do this task ?

    Please assist ?

    Rgds,
    Aligahk06

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]
    Option Explicit
    Option Compare Text
    Sub Data()
    Dim Arr, a
    Dim Rng As Range, cel As Range
    Dim i As Long
    Dim Del As Boolean
    Arr = Array("PIPE", "ELL", "TEE", "REDUCER", "VALVE", "CAP")
    Set Rng = Range(Cells(3, 1), Cells(Rows.Count, 1).End(xlUp))
    For i = Rng(Rng.Cells.Count).Row To Rng.Cells(1).Row + 1 Step -1
    Del = True
    For Each a In Arr
    If InStr(1, Cells(i, 1), a) > 0 Then
    Cells(i, 6) = Cells(i, 3)
    Cells(i, 7) = Cells(i, 4)
    Cells(i, 9) = a
    Del = False
    End If
    Next
    If Del Then Cells(i, 1).EntireRow.Delete
    Next
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Quote Originally Posted by mdmackillop
    [VBA]
    Option Explicit
    Option Compare Text
    Sub Data()
    Dim Arr, a
    Dim Rng As Range, cel As Range
    Dim i As Long
    Dim Del As Boolean
    Arr = Array("PIPE", "ELL", "TEE", "REDUCER", "VALVE", "CAP")
    Set Rng = Range(Cells(3, 1), Cells(Rows.Count, 1).End(xlUp))
    For i = Rng(Rng.Cells.Count).Row To Rng.Cells(1).Row + 1 Step -1
    Del = True
    For Each a In Arr
    If InStr(1, Cells(i, 1), a) > 0 Then
    Cells(i, 6) = Cells(i, 3)
    Cells(i, 7) = Cells(i, 4)
    Cells(i, 9) = a
    Del = False
    End If
    Next
    If Del Then Cells(i, 1).EntireRow.Delete
    Next
    End Sub
    [/VBA]
    Dear Sir,
    Can u explain how the code is working.
    I am a little bit confused about the syntax and flow.
    Please explain?
    Help is deeply welcome.


    Rgds,
    Aligahk06

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Aligahk06, please make sure you post the links here to all your cross posts, this means adding the url of each and every forum that you posted this question in, you have already had a formula based answer in the Microsoft Newsgroups!

    Read the cross post link in my signature for an explanation why.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    Soory, I didn't know the rule? I will not repeat in future.
    Thanks for your time.

Posting Permissions

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