PDA

View Full Version : How to integrate an undo command into conditional formatting VBA code



Rol
10-09-2008, 05:35 PM
This project uses the very helpful VBA code from "conditional formatting (more than three)" by "DRJ" (thankyou!). To find the VBA code just search for "Conditional Formatting (More Than Three)" on this website

With this code I can format any cell. Eg, by typing the letters "gp" and then pressing enter, the background colour of the cell changes to yellow. However, at the moment, I'm unable to undo any changes.

I would like to integrate this undo command I've found from a webpage that can be found by using Google to search for "undoing_a_vba_subroutine". The website is called The Spreadsheet Page

The problem I have is that I don't know how to integrate the undo command into the conditional formatting VBA code. Can anyone help?

I've attached two files that show the conditional formatting and the undo command working OK separately. How can I get them to work together?

MaximS
10-09-2008, 06:27 PM
Whats the point of using undo when pressing Delete or typing anything else is solving the problem?

Bob Phillips
10-10-2008, 12:49 AM
It won';t be an undo stack like Excel has, it will realistically only be the last action. Is that of any real use?

Rol
10-10-2008, 02:25 AM
Thanks for your responses. Here are are my replies to posts 2 and 3:


Whats the point of using undo when pressing Delete or typing anything else is solving the problem?
Thanks for your reply. What I'd like to do it have unlimited undos so I can undo many times. If you download "undo-command.xls" from the attached files from my first post you'll get an idea of what I'm looking for.


It won';t be an undo stack like Excel has, it will realistically only be the last action. Is that of any real use?
Thanks - yes, this might help as it could put me in the right direction. The difficulty I'm having is trying to make both sets of code work together. The code for the conditional formatting is inside:


Private Sub Worksheet_Change(ByVal Target As Range)
End Sub


Whereas the code for the multiple undos is a set of subroutines below the following:


Type SaveRange
Val As Variant
Addr As String
End Type

Public OldWorkbook As Workbook
Public OldSheet As Worksheet
Public OldSelection() As SaveRange


Hopefully you'll see what I mean when you view the files attached to the first post which are now downloadable: "conditional-formatting.xls" and "undo-command.xls"