+ Reply to Thread
Results 1 to 7 of 7

Delete adjacent cell

Hybrid View

kryt0n Delete adjacent cell 10-12-2011, 09:26 AM
Andrew-R Re: Delete adjacent cell 10-12-2011, 09:49 AM
kryt0n Re: Delete adjacent cell 10-12-2011, 09:54 AM
Andrew-R Re: Delete adjacent cell 10-12-2011, 10:06 AM
kvsrinivasamurthy Re: Delete adjacent cell 10-12-2011, 10:28 AM
Andrew-R Re: Delete adjacent cell 10-12-2011, 10:39 AM
kryt0n Re: Delete adjacent cell 10-12-2011, 10:39 AM
  1. #1
    Forum Contributor
    Join Date
    04-08-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    228

    Delete adjacent cell

    Hi,

    please see the .xls attached.

    I have 4 coloumns each with a named range list.

    Titles in Row 1. Contents in Row 2.

    I want it so that whichever of the cells you select then DELETE OR CHANGE then all following cells become empty. If you change C2, then D2 becomes empty. If you change A2, then B2, C2 and D2 become empty.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Delete adjacent cell

    I've added the following macro to your sheet change event code ...

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Const sNAMERANGE = "A2:D2"
    
    Dim rngCellLoop As Range
    
    If Not Intersect(Range(sNAMERANGE), Target) Is Nothing Then
    
      Application.EnableEvents = False
      
      For Each rngCellLoop In Range(sNAMERANGE).Cells
        If rngCellLoop.Column > Target.Column Then
          rngCellLoop.Value = ""
        End If
      Next rngCellLoop
      
      Application.EnableEvents = True
      
    End If
      
    End Sub

    The updated workbook is attached.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    04-08-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    228

    Re: Delete adjacent cell

    That's perfect! Last question, what would I need to change here if I had more than one row? Ie, if I had rows 2,3,4,5 filled in?

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Delete adjacent cell

    Do you want only the cells on the same row as the deleted/updated cell to be cleared?

    If so you could change the code to:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Const sNAMERANGE = "A2:D5"
    
    Dim rngCellLoop As Range
    
    If Not Intersect(Range(sNAMERANGE), Target) Is Nothing Then
    
      Application.EnableEvents = False
      
      For Each rngCellLoop In Intersect(Range(sNAMERANGE),Rows(Target.Row)).Cells
        If rngCellLoop.Column > Target.Column Then
          rngCellLoop.Value = ""
        End If
      Next rngCellLoop
      
      Application.EnableEvents = True
      
    End If
      
    End Sub

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Delete adjacent cell

    pl see attached file.For sheet1 worksheetchange code added which meets your requirement.
    Regards.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Delete adjacent cell

    Quote Originally Posted by kvsrinivasamurthy View Post
    code added which meets your requirement.
    Not wishing to be rude, but you perhaps need to re-read the requirements.

  7. #7
    Forum Contributor
    Join Date
    04-08-2009
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2003
    Posts
    228

    Re: Delete adjacent cell

    Hi kvsrinivasamurthy,

    can you put the code in the thread please? I can't download documents currently.

+ 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