Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 33
Default VBA code to undo previous VBA action

I was wondering if code can be written to undo a previous vba action.
Specifically I have a range of cell that I clear with some vba code. Was
wondering if code can be written recall what was previsiouly cleared? I
found that I can do it with just one cell, but I'm working with a range of
cells and can't seem to get it to work.

Here's the code I use to clear my contents.

Sub ClearMasterAttendance()
Range("'Lunch and Attendance'!AD7:BH22").Select
Selection.ClearContents

End Sub

Now can anyone please help me with some code to undo this action.

Thanks,
--
Mike Mast
Special Education Preschool Teacher
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default VBA code to undo previous VBA action

Have ClearMasterAttendance first save the block of data in a working area and
then clear it. The Undo macro would just copy the saved area back.
--
Gary''s Student - gsnu200906


"Preschool Mike" wrote:

I was wondering if code can be written to undo a previous vba action.
Specifically I have a range of cell that I clear with some vba code. Was
wondering if code can be written recall what was previsiouly cleared? I
found that I can do it with just one cell, but I'm working with a range of
cells and can't seem to get it to work.

Here's the code I use to clear my contents.

Sub ClearMasterAttendance()
Range("'Lunch and Attendance'!AD7:BH22").Select
Selection.ClearContents

End Sub

Now can anyone please help me with some code to undo this action.

Thanks,
--
Mike Mast
Special Education Preschool Teacher

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA code to undo previous VBA action

Take a look at John Walkenbach's site:
http://spreadsheetpage.com/index.php...ba_subroutine/

He saves multiple cell ranges.

Preschool Mike wrote:

I was wondering if code can be written to undo a previous vba action.
Specifically I have a range of cell that I clear with some vba code. Was
wondering if code can be written recall what was previsiouly cleared? I
found that I can do it with just one cell, but I'm working with a range of
cells and can't seem to get it to work.

Here's the code I use to clear my contents.

Sub ClearMasterAttendance()
Range("'Lunch and Attendance'!AD7:BH22").Select
Selection.ClearContents

End Sub

Now can anyone please help me with some code to undo this action.

Thanks,
--
Mike Mast
Special Education Preschool Teacher


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 33
Default VBA code to undo previous VBA action

Sorry, but what exactly do you mean by "working area"? Another cell range?
or declare it with a Dim statement? I tried several Dim statements Integer,
Long, Double, but none work. The only one I could get to work was Variant.
Is it ok to use Dim Undo As Variant? Do you forsee any problems with this
type of declaration?
--
Mike Mast
Special Education Preschool Teacher


"Gary''s Student" wrote:

Have ClearMasterAttendance first save the block of data in a working area and
then clear it. The Undo macro would just copy the saved area back.
--
Gary''s Student - gsnu200906


"Preschool Mike" wrote:

I was wondering if code can be written to undo a previous vba action.
Specifically I have a range of cell that I clear with some vba code. Was
wondering if code can be written recall what was previsiouly cleared? I
found that I can do it with just one cell, but I'm working with a range of
cells and can't seem to get it to work.

Here's the code I use to clear my contents.

Sub ClearMasterAttendance()
Range("'Lunch and Attendance'!AD7:BH22").Select
Selection.ClearContents

End Sub

Now can anyone please help me with some code to undo this action.

Thanks,
--
Mike Mast
Special Education Preschool Teacher

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 33
Default VBA code to undo previous VBA action

Thanks for the suggestion, but this is all very new to me and I don't know
how to adjust the code on his site for my situation.
--
Mike Mast
Special Education Preschool Teacher


"Dave Peterson" wrote:

Take a look at John Walkenbach's site:
http://spreadsheetpage.com/index.php...ba_subroutine/

He saves multiple cell ranges.

Preschool Mike wrote:

I was wondering if code can be written to undo a previous vba action.
Specifically I have a range of cell that I clear with some vba code. Was
wondering if code can be written recall what was previsiouly cleared? I
found that I can do it with just one cell, but I'm working with a range of
cells and can't seem to get it to work.

Here's the code I use to clear my contents.

Sub ClearMasterAttendance()
Range("'Lunch and Attendance'!AD7:BH22").Select
Selection.ClearContents

End Sub

Now can anyone please help me with some code to undo this action.

Thanks,
--
Mike Mast
Special Education Preschool Teacher


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default VBA code to undo previous VBA action

Here is some sample coding. We are using a spare area to store a copy.

Sub ClearMasterAttendance()
Dim sh As Worksheet
Dim DataBlock As Range
Dim UndoBlock As Range
Set sh = Sheets("Lunch and Attendance")
Set DataBlock = sh.Range("AD7:BH22")
Set UndoBlock = sh.Range("ET1:FX16")
DataBlock.Copy UndoBlock
DataBlock.ClearContents
End Sub

Sub undo()
Dim sh As Worksheet
Dim DataBlock As Range
Dim UndoBlock As Range
Set sh = Sheets("Lunch and Attendance")
Set DataBlock = sh.Range("AD7:BH22")
Set UndoBlock = sh.Range("ET1:FX16")
UndoBlock.Copy DataBlock
End Sub

If ET1:FX16 is not usable, pick another spare area.
--
Gary''s Student - gsnu200906


"Preschool Mike" wrote:

Sorry, but what exactly do you mean by "working area"? Another cell range?
or declare it with a Dim statement? I tried several Dim statements Integer,
Long, Double, but none work. The only one I could get to work was Variant.
Is it ok to use Dim Undo As Variant? Do you forsee any problems with this
type of declaration?
--
Mike Mast
Special Education Preschool Teacher


"Gary''s Student" wrote:

Have ClearMasterAttendance first save the block of data in a working area and
then clear it. The Undo macro would just copy the saved area back.
--
Gary''s Student - gsnu200906


"Preschool Mike" wrote:

I was wondering if code can be written to undo a previous vba action.
Specifically I have a range of cell that I clear with some vba code. Was
wondering if code can be written recall what was previsiouly cleared? I
found that I can do it with just one cell, but I'm working with a range of
cells and can't seem to get it to work.

Here's the code I use to clear my contents.

Sub ClearMasterAttendance()
Range("'Lunch and Attendance'!AD7:BH22").Select
Selection.ClearContents

End Sub

Now can anyone please help me with some code to undo this action.

Thanks,
--
Mike Mast
Special Education Preschool Teacher

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA code to undo previous VBA action

Try some things.

Post back with your specific questions.

Preschool Mike wrote:

Thanks for the suggestion, but this is all very new to me and I don't know
how to adjust the code on his site for my situation.
--
Mike Mast
Special Education Preschool Teacher

"Dave Peterson" wrote:

Take a look at John Walkenbach's site:
http://spreadsheetpage.com/index.php...ba_subroutine/

He saves multiple cell ranges.

Preschool Mike wrote:

I was wondering if code can be written to undo a previous vba action.
Specifically I have a range of cell that I clear with some vba code. Was
wondering if code can be written recall what was previsiouly cleared? I
found that I can do it with just one cell, but I'm working with a range of
cells and can't seem to get it to work.

Here's the code I use to clear my contents.

Sub ClearMasterAttendance()
Range("'Lunch and Attendance'!AD7:BH22").Select
Selection.ClearContents

End Sub

Now can anyone please help me with some code to undo this action.

Thanks,
--
Mike Mast
Special Education Preschool Teacher


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i undo an action after i have clicked save. missy Excel Discussion (Misc queries) 2 December 8th 08 05:43 PM
How to undo the delete action? ABS Excel Discussion (Misc queries) 2 April 16th 08 05:30 PM
Undo delete button action lwj Excel Worksheet Functions 0 June 15th 07 03:33 PM
Undo a save action John Excel Discussion (Misc queries) 1 January 26th 06 06:26 PM
undo/redo action dmuraki Excel Discussion (Misc queries) 3 November 30th 04 12:11 AM


All times are GMT +1. The time now is 12:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"