+ Reply to Thread
Results 1 to 3 of 3

Macro to undo sub

Hybrid View

  1. #1
    Registered User
    Join Date
    09-25-2013
    Location
    Phoenix
    MS-Off Ver
    Excel 2007
    Posts
    61

    Macro to undo sub

    Hi, I am looking for some code that would undo the below sub. The sub searches a table and pulls data of cells based on cell color. It continuously populates the Sheet "ALLmissed" and adds to the last used row in the sheet. I would like the undo to only undo the most recent update, and to keep the previous data that exists from previous times running the sub. I appreciate any help!

    Sub If_Red_Copy_to_ALLmissed()
    Dim icell As Range, myRange As Range
    Dim endcell As Range
    Dim index As Long
    Set myRange = Union(Range("B3:B80"), Range("F3:F80"), Range("J3:J80"), Range("N3:N80"), Range("R3:R80"))
    
    For Each icell In myRange
        If icell.Interior.Color = RGB(255, 0, 0) Then
            With Sheets("ALLmissed")
                index = .Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
                .Cells(index, 3).Value = icell.Value
                .Cells(index, 4).Value = icell.Offset(0, 1).Value
                .Cells(index, 6).Value = icell.Offset(0, 2).Value
                .Cells(index, 11).Value = Now()
                .Cells(index, 1).Formula = "=" & index & "-1"
                .Cells(index, 2).Formula = "=WEEKNUM(NOW())-1"
                .Cells(index, 9).Formula = "=VLOOKUP($C" & index & ", enginelist!$A$2:$B$150, 2, FALSE)"
                .Cells(index, 10).Formula = "=VLOOKUP($C" & index & ", enginelist!$A$2:$C$150, 3, FALSE)"
            index = index + 1
            End With
        End If
    Next icell
    End Sub

  2. #2
    Registered User
    Join Date
    02-26-2013
    Location
    Riverside
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to undo sub

    Why not Time/Date stamp your data, and create a macro that deletes data by referencing this?

  3. #3
    Registered User
    Join Date
    09-25-2013
    Location
    Phoenix
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Macro to undo sub

    That could work, I already have the time stamp written in:
    .Cells(index, 11).Value = Now()
    Let's say I would want it to delete anything within the last hour...how would I go about doing that? Sorry I am pretty new to this.

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Can't Undo due to Macro
    By Bjourne in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-11-2012, 04:16 AM
  2. Replies: 0
    Last Post: 02-29-2012, 01:40 PM
  3. Undo function to undo Visual Basic commands
    By pierre08 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2010, 04:59 AM
  4. Macro for undo
    By prabodh1234 in forum Excel General
    Replies: 3
    Last Post: 07-09-2009, 11:10 AM
  5. Undo a macro
    By drgogo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2009, 05:11 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