+ Reply to Thread
Results 1 to 3 of 3

Clear contents in one cell when contents of another cell are deleted

Hybrid View

  1. #1
    Registered User
    Join Date
    12-20-2012
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2007
    Posts
    14

    Cool Clear contents in one cell when contents of another cell are deleted

    New to the forum and have a quick VBA question.

    The specified target cell is a drop down validation box with text. If the user deletes the text in the target cell, I want to clear the formula in the corresponding cell that is 7 columns to the right. Here is the code I have now that does not work:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
       If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
        
       If Target.Value = Cells(Rows.Count, "J").End(xlUp).Value Then
      
               On Error Resume Next
                    Application.EnableEvents = False
            Dim rRange As Range
            Dim rRange2 As Range
            Set rRange = Target.Offset(0, 7)
            Set rRange2 = Target.Offset(-1, 7)
            rRange2.Copy
            rRange.PasteSpecial (xlPasteAll)
            Application.CutCopyMode = False
                    Application.EnableEvents = True
                             On Error GoTo 0
            Else
                 rRange.ClearContents
    End If
        
    End Sub
    What changes do I need to make?

    Any help much appreciated - Bob B

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Clear contents in one cell when contents of another cell are deleted

    why dont you do this with a regulat formula? something like =if(target cell ="","",your-original-formula)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Clear contents in one cell when contents of another cell are deleted

    Not sure what you have going on with the copy stuff, but for the clearing 7 cells to the right when column J target is deleted...

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Cells.Count > 1 Then Exit Sub
        If Target.Column <> 10 Then Exit Sub
        If Not Intersect(Target, Range("J:J")) Is Nothing Then
            Application.EnableEvents = False
            If Target.Value = "" Then Target.Offset(, 7).ClearContents
            Application.EnableEvents = True
        End If
    End Sub
    HTH
    Regards, Jeff

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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