Results 1 to 13 of 13

Delete Cell Contents when macro runs

Threaded View

  1. #1
    Registered User
    Join Date
    06-17-2013
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2011
    Posts
    26

    Delete Cell Contents when macro runs

    Below is my current code that is working fine. The Macro runs when I type a value into cell G2, it then adds the value of G2 to cell G4, G5, G6, G7, or G8 depending on the date. What code can I add to this so that once the macro adds G2 to the other cell, it would then delete the contents of cell G2?

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim nRw As Long, rCell As Range
    Set rCell = Range("A1")
    
            'My CODE FOR G ________________________________________________
    If Target.Address = "$G$2" Then
                           
                If rCell.Value = "" Then
                    MsgBox "No Value Found", vbInformation, "Input Required"
                    Exit Sub
                End If
                
                On Error GoTo NoMatchFound:
                nRw = Range("A:A").Find(rCell.Value).Row
                
                With Cells(nRw, "G")
                    .Value = .Value + Range("G2").Value
                End With
            Exit Sub
    
                    'My CODE FOR H ________________________________________________
    ElseIf Target.Address = "$H$2" Then
                                           
                        If rCell.Value = "" Then
                            MsgBox "No Value Found", vbInformation, "Input Required"
                            Exit Sub
                        End If
                        
                        On Error GoTo NoMatchFound:
                        nRw = Range("A:A").Find(rCell.Value).Row
                        
                        With Cells(nRw, "H")
                            .Value = .Value + Range("H2").Value
                        End With
                        
                        Exit Sub
                        
                          'My CODE FOR I ________________________________________________
    ElseIf Target.Address = "$I$2" Then
                                           
                        If rCell.Value = "" Then
                            MsgBox "No Value Found", vbInformation, "Input Required"
                            Exit Sub
                        End If
                        
                        On Error GoTo NoMatchFound:
                        nRw = Range("A:A").Find(rCell.Value).Row
                        
                        With Cells(nRw, "I")
                            .Value = .Value + Range("I2").Value
                        End With
                        
                        Exit Sub
    NoMatchFound:
                            MsgBox "No Match Found", vbCritical, "Task Un-Successfull"
    End If
    
    
    End Sub
    Last edited by brown3218; 09-09-2013 at 11:23 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Delete Cell Value after Macro Runs
    By brown3218 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-20-2013, 11:42 AM
  2. [SOLVED] Macro to delete certain contents of a cell
    By SpyderPB6 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2012, 07:16 PM
  3. Macro to delete entire row based on cell contents
    By ATX in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-06-2011, 03:52 AM
  4. Macro to delete cell contents in every other column
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-01-2010, 12:29 PM
  5. [SOLVED] VBA Excel Macro to delete contents in named cell
    By reaa in forum Excel General
    Replies: 1
    Last Post: 01-03-2006, 04:20 PM

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