+ Reply to Thread
Results 1 to 2 of 2

Retaing a varialbe between running the same macro

  1. #1
    Jack Gillis
    Guest

    Retaing a varialbe between running the same macro

    Over my head here? You betcha!

    I have put together a macro that examines the colorIndex of a cell and
    stores it in an integer variable called intial_cell_color. the macro
    then changes the color index of that cell and exits. I need to be able
    to restore the original colorIndex to that cell or another later on by
    running another or the same macro. Clearly, the variable will lose its
    lifetime when the first macro exits. Is there a way I can store
    initial_cell_color somewhere and have it available when I run another
    macro or the first one again.

    I have tried using an object variable but can figure out how to store
    the colorIndex in it.

    Will someone please suggest a way to do what I want to do? That is
    retrieve the colorIndex of a cell or range of cells, store it somewhere
    so I can restore it later on?

    Thank you.



  2. #2
    Niek Otten
    Guest

    Re: Retaing a varialbe between running the same macro

    Declare the variable Static. "Static" replaces "Dim".

    --

    Kind Regards,

    Niek Otten

    Microsoft MVP - Excel


    "Jack Gillis" <[email protected]> wrote in message
    news:[email protected]...
    > Over my head here? You betcha!
    >
    > I have put together a macro that examines the colorIndex of a cell and
    > stores it in an integer variable called intial_cell_color. the macro then
    > changes the color index of that cell and exits. I need to be able to
    > restore the original colorIndex to that cell or another later on by
    > running another or the same macro. Clearly, the variable will lose its
    > lifetime when the first macro exits. Is there a way I can store
    > initial_cell_color somewhere and have it available when I run another
    > macro or the first one again.
    >
    > I have tried using an object variable but can figure out how to store the
    > colorIndex in it.
    >
    > Will someone please suggest a way to do what I want to do? That is
    > retrieve the colorIndex of a cell or range of cells, store it somewhere so
    > I can restore it later on?
    >
    > Thank you.
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1