Solved

VBA excel, Copy Row to Memory for Later UnDo

Posted on 2011-09-10
5
342 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
My experience with Windows 10 over a one year period and suggestions for smooth operation
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now