Excel: Macro with conditional format problem

Microsoft Microsoft office excel 2007 ac...
May 24, 2011 at 08:03:52
Specs: Windows XP
Hi,

I would like to create a macro with conditional formating (3 rules). I have recorded a macro but when I have to set the conditional format, I have to select a field or cell.
However, the field I will have to run the macro on will change from one Excel file to another one.
Is it possible not to select any speficic area for the macro and just select the area just before running this macro (by highlighting the field)?
I really do not think that it is complicated but I do not know how to do it.

I hope this makes sense.
Please help me.

Thanks a lot.

Aurelie


See More: Excel: Macro with conditional format problem

Report •


#1
May 24, 2011 at 12:17:39
re: "Is it possible not to select any speficic area for the macro and just select the area just before running this macro?"

Well, that's as clear as mud...

I assume that you mean that the recorder hard-coded a range into the macro, but you want to manually select a range and have the macro operate on the currently selected range.

Without seeing your code, it's impossible to say that the following suggestion will work, but I'll toss it out there anyway:

If the recorder gave you this:

    
Range("A1:B10").Select
Selection.FormulaR1C1 = "Data"

then the word Data will appear in A1:B10.

If you select your own range and then use just this line:

    
Selection.FormulaR1C1 = "Data"

then the word Data will appear in each of the currently selected cells in the active sheet.

Of course, it depends on what your macro is doing in order for it to work on the selected range.

For example, if you select A1 and run this code, you'll get an error since the macro can't operate on a non-existent cell:

Selection.Offset(-1, -1).FormulaR1C1 = "Data"

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •
Related Solutions


Ask Question