Solved

VBA excel, Copy Row to Memory for Later UnDo

Posted on 2011-09-10
5
344 Views
Last Modified: 2012-05-12
I have a form with 3 CommandButtons.  
1. "Copy Row"  Button
2. "Clear Values" Button
3. "UnDo Row" Button

Here are the Click Actions for each Button:

Private Sub Copy_Row_Click()

      ' ....???? Selection.EntireRow ....Copy to Memory ???

End Sub


Private Sub Clear_Values_Click()

          Selection.EntireRow.Clear

End Sub


Private Sub Undo_Row_Click()

  ' ....???? Selection.EntireRow ......bring back the old Row....???..

End Sub

Open in new window



I am trying to find a way so that, when I hit the Button "Copy_Row" and Then Button "Clear Values"  to be able (if I decide at a later stage) to bring the entire cleared Row (with its Values and its Formulas) back to place.....

I am not looking for the standard method of copying the whole file because it is very big and it will slow the procedures down....

Thanks in advance,
Any ideas?

0
Comment
Question by:New_Alex
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 500 total points
ID: 36516977
If you only ever wanted to be able to recover the most recently deleted row, you could store its values in a variant array, the restore them later.  But this would only restore values/formulas, not formatting:

Private mvSavedRow

Private Sub Copy_Row_Click()

      ' ....???? Selection.EntireRow ....Copy to Memory ???
      mvSavedRow = Application.Intersect(Selection.EntireRow, ActiveSheet.UsedRange).Formula

End Sub


Private Sub Clear_Values_Click()

          Selection.EntireRow.Clear

End Sub


Private Sub Undo_Row_Click()

  ' ....???? Selection.EntireRow ......bring back the old Row....???..
  Dim rng As Excel.Range
  
  Set rng = Selection.Cells(1)
  rng.Resize(1, UBound(mvSavedRow, 2)).Formula = mvSavedRow

End Sub

Open in new window

0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36516979
If you wanted formats and everything, you would probably have to copy the row to another (hidden?) sheet, then copy it back again
0
 
LVL 1

Author Comment

by:New_Alex
ID: 36517098
Hi andrew.

Is it possible to save the Row in a closed Workbook file and then retrieve it while workbook remains closed?

Thank you... Presentation is important for me!
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36517192
You couldn't save it in a closed workbook - it would have to be open in Excel to write to it and read from it. The first suggestion I made would not show anything to the user. If formatting is important you could possibly copy it from another row.
0
 
LVL 1

Author Closing Comment

by:New_Alex
ID: 36540789
Yes very good solution but limited. There are probably not a lot of things you can do generally for this
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question