+ Reply to Thread
Results 1 to 6 of 6

Conditional Formatting & VBA Code

  1. #1
    Forum Contributor
    Join Date
    12-04-2006
    Posts
    201

    Conditional Formatting & VBA Code

    Hi,

    I am currently using "Private Sub WorkBOOK_BeforeSave" code to ensure that if certain cells are not filled in then the file will not save.

    Does anyone know any code that will allow me to stop the file from saving if CONDITIONAL FORMATTING is active in a cell or if a cell turns red through conditional formatting to stop it saving???

    thanks in advance

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Sharp
    Hi,

    I am currently using "Private Sub WorkBOOK_BeforeSave" code to ensure that if certain cells are not filled in then the file will not save.

    Does anyone know any code that will allow me to stop the file from saving if CONDITIONAL FORMATTING is active in a cell or if a cell turns red through conditional formatting to stop it saving???

    thanks in advance
    Hi,

    why not just test the condition that would cause the Format to display Red?

    ---
    Si fractum non sit, noli id reficere.

  3. #3
    Forum Contributor
    Join Date
    12-04-2006
    Posts
    201
    Hi,

    thanks...

    sorry not very good with VBA code...could you be more specific

    thanks

  4. #4
    Registered User
    Join Date
    01-19-2007
    Posts
    24
    I think he means to use the same test that the conditional formatting uses.
    For example, if the conditional formatting turns a cell Red when the number is negative, then you test the cell contents for negative numbers before allowing a save.

  5. #5
    Forum Contributor
    Join Date
    12-04-2006
    Posts
    201
    Oh...

    the problem with that is the cell may turn red, depending on the data in a number of other cells. Sometimes it may be ok to be empty and other times it may not.

    For example;

    If cell 'A1' is YES then 'B1' needs to have a number in it and conditional formatting will turn 'B1' red until a number is empty.

    If cell 'A1' is NO then 'B1' doesn't need to have a number in it and conditional formatting will not activate and the cell can be left empty

  6. #6
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Sharp
    Oh...

    the problem with that is the cell may turn red, depending on the data in a number of other cells. Sometimes it may be ok to be empty and other times it may not.

    For example;

    If cell 'A1' is YES then 'B1' needs to have a number in it and conditional formatting will turn 'B1' red until a number is empty.

    If cell 'A1' is NO then 'B1' doesn't need to have a number in it and conditional formatting will not activate and the cell can be left empty
    Hi,

    so whatever code is in the Conditional Format formula for 'Red' needs to be used in your 'before_close' routine, where something like If UCase(Cells(1,1).value) = "YES" And Cells(1,2).value <> "" then should go close.

    hth
    ---

+ 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