Results 1 to 10 of 10

Thread: Excel VBA Delete after timer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,970
    Try something along these lines:
    Sub Cache()
    Dim NoOfCrew As Long
    NoOfCrew = Sheets("Cache").Cells(Rows.Count, "A").End(xlUp).Row
    NoOfCrew = NoOfCrew + 1
    Sheets("Hotel Booking").Range("Q10:U19").Copy
    Sheets("Cache").Range("A" & NoOfCrew).PasteSpecial
    Sheets("Hotel Booking").Range("X10:X19").Copy
    Sheets("Cache").Range("F" & NoOfCrew).PasteSpecial
    myName = "Range" & Timer 'invent a random-ish name
    Sheets("Cache").Range("A" & NoOfCrew).Resize(10, 6).Name = myName 'give the range that's just been copied to that name
    Application.CutCopyMode = False
    DelayMacro myName 'pass that name onto the DelayMacro macro
    End Sub
    
    Sub Delete(theRange)
    Range(theRange).Delete shift:=xlUp 'deletes the range itself
    Names(theRange).Delete 'deletes the Name
    End Sub
    
    Sub DelayMacro(myStr)
    Application.OnTime Now() + TimeValue("00:00:10"), "'Delete """ & myStr & """'" 'sets up a timed call of the Delete macro passing the name of the named range so it knows what to delete
    End Sub
    Last edited by p45cal; 07-11-2018 at 11:01 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •