+ Reply to Thread
Results 1 to 6 of 6

Identify Cells with value of 0 and delete 0 cell and adjacent cell

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2013
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Excel 2007
    Posts
    28

    Identify Cells with value of 0 and delete 0 cell and adjacent cell

    Hello,

    I am having trouble writing a macro that both identifies cells with a value of 0 within a range and then deletng that cell and the cell to the immediate left. Ideally this macro would clear both cells and move the rest of the data up one row.

    Thank you!

    Sam

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Identify Cells with value of 0 and delete 0 cell and adjacent cell

    Hi Sam.

    You need a select special Macro.

    I think that you want just those two cells deleted not the entire row.

    BRB

  3. #3
    Registered User
    Join Date
    02-20-2013
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Identify Cells with value of 0 and delete 0 cell and adjacent cell

    Correct, I only want those two cells deleted so that the cells below them will move up. I need the data to be without blanks so that I can bring it over to another worksheet without causing system issues after the workbook is finalized.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Identify Cells with value of 0 and delete 0 cell and adjacent cell

    Here is your code.

    Enjoy.



    Sub Select_Special()
    Dim rngFind As Range
        Dim strValueToPick As String
        Dim rngPicked As Range
        Dim rngLook As Range
        Dim strFirstAddress As String
    
        Range("A:A").Select
        
        Set rngLook = Selection
        strValueToPick = "0"
        With rngLook
            Set rngFind = .Find(strValueToPick, .Cells(1, 1), LookIn:=xlValues, lookat:=xlWhole)
            If Not rngFind Is Nothing Then
                strFirstAddress = rngFind.Address
                Set rngPicked = Range(rngFind, Cells(rngFind.Row, rngFind.Column + 1))
                Do
                    Set rngPicked = Union(rngPicked, Range(rngFind, Cells(rngFind.Row, rngFind.Column + 1)))
                    Set rngFind = .FindNext(rngFind)
                Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstAddress
            End If
        End With
        
        If Not rngPicked Is Nothing Then
            rngPicked.Select
        Selection.Delete Shift:=xlUp
        End If
        
    
    End Sub

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Identify Cells with value of 0 and delete 0 cell and adjacent cell

    The line
    Range("A:A").Select
    Is where you select your range, modify that to suit your requirement.

  6. #6
    Registered User
    Join Date
    02-20-2013
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Identify Cells with value of 0 and delete 0 cell and adjacent cell

    Thank you mehmetcik!

+ 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