+ Reply to Thread
Results 1 to 23 of 23

conditional formatting with vba

  1. #1
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    conditional formatting with vba

    Hello everyone,
    this macro:
    Please Login or Register  to view this content.
    need for conditional formatting of the range E4: AI39.
    I ask for help for a change.
    Deleting a volore inserted for example "A" the cell must go with the original color, must not remain yellow.
    I hope I explained.
    max_max

    -----------------------------------------------------------------------------------------------------------

    Ciao a tutti,
    questa macro:

    ,,
    ,,
    ,,
    ,,
    ,,

    serve per la formattazione condizionale del range E4:AI39.
    Io chiedo un aiuto per una modifica.
    Cancellando un volore inserito per esempio A la cella deve tornare con il colore originale, non deve restare gialla.
    Io spero di essermi spiegato.
    max_max
    Last edited by max_max; 03-28-2015 at 07:54 AM.

  2. #2
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    I am attaching an example:
    ABCD.xls
    Also included is a formatting:
    = MOD (ROW (), 2) = 1
    max_max
    -------------------------------
    Allego un esempio:
    ,,
    ,,
    ,,
    E'inserita una formula per formattazione condizionale:
    =RESTO(RIF.RIGA();2)=1
    max_max

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, may_max,

    CF will override your formatting on the coloured rows - you would need to use VBA as well to get the colours on and off.

    Please Login or Register  to view this content.
    You should restrict the code to work for only those cells invoked and not the whole range.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    Hello hahobe,
    works almost fine, thanks you.
    If I delete a single letter the cell returns with its color, if I cancel more than one letter color is yellow.
    You can not take priority to conditional formatting.
    max_max
    ------------------------------------------------------------------------------------------------------------------
    Ciao hahobe,
    funziona quasi bene, grazie.
    Se cancello una sola lettera la cella ritorna con il suo colore, se cancello più di una lettera il colore resta giallo.
    Non si può togliere la priorità alla formattazione condizionale.
    max_max

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    exactly what he codeline
    Please Login or Register  to view this content.
    wants the code to do.

    You would need to work with areas in order to get the code working for more than one cell like
    Please Login or Register  to view this content.
    as you have not made clear if you have a continuous number of cells or if these might be single cells as well.

    Ciao,
    Holger

  6. #6
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    I hope to explain.
    The range is E4: AI39 and the cells can be both direct and alternating.
    max_max
    ----------------------------------------------------------------------------
    Spero di spiegarmi.
    Il range è E4:AI39 e le celle possono essere sia continue che alternate.
    max_max

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    when I tested the code before posting here I used single cells and thus worked with Selection.

    Ciao,
    Holger

  8. #8
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    I tried the new code, but does not change the color.
    ABCDE.xls
    max_max

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    sorry could you tell me where the code isn´t working? If it´s inside the range filled by CF that´s normal due to you mixing up standard features and VBA with CF being on top of the list and not allowing changes if the cell is coloured..

    Ciao,
    Holegr

  10. #10
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    Conditional Formatting > = MOD (ROW (), 2) = 1
    range A4:AJ39
    formatting to alternating rows colored
    ----------------------------------------------------------
    Formattazione condizionale > =RESTO(RIF.RIGA();2)=1
    range A4:AJ39
    formattazione per righe colorate alternate
    Last edited by max_max; 03-28-2015 at 10:49 AM.

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    again: if you apply Conditional Formatting this will overwrite any VBA code and colours. In addition I can´t see any reason why CF is being used on a static range instead of switching to VBA for doing this and getting the proper results (at least what I understand from the request).

    Code for colouring the range:
    Please Login or Register  to view this content.
    Code behind the Sheet:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Attached Files Attached Files

  12. #12
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    Thanks hahobe,
    I tried your new change but the cells of the range E4: AJ39 not always stain.
    See attached photo
    max_max
    --------------------------------------------------------------------------------------
    Grazie hahobe,
    ho provato la tua nuova modifica ma le celle del range E4:AJ39 non sempre si colorano.
    Vedi foto allegata.
    max_max

    Appunti01.jpg

  13. #13
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    you would need to explain what you expect the code to do and what it´s not doing although I suspect that you would need to run another code once before you apply the Worksgheet_Change-event. But you never mentioned that and I´m afraid I ran out of guessing of what users may think the code should be doing woithout explicitely mention it.

    Ciao,
    Holger

  14. #14
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    please change the macro to set up the sheet in the sample to
    Please Login or Register  to view this content.
    As long as macros are enabled when working with the workbook the Worksheet_Change-event should handle any changes with the area. That´s why I went away from running through the entire area on each change to any cell in the area and tried to narrow down the number of cells to be checked.

    Ciao,
    Holger

  15. #15
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    Hello hahobe.
    I did as you wrote (I hope you understand).
    The colors should be automatic and not clicking on the button.
    If I delete more than one cell color formatting remains.
    max_max
    ---------------------------------------------------------------------------
    Ciao hahobe.
    Ho fatto come hai scritto (spero di aver capito).
    I colori dovrebbero essere automatici e non cliccando nel pulsante.
    Se cancello più di una cella il colore della formattazione resta.
    max_max

    max_29_03.xls

  16. #16
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    tested my latest code in addition with the Worksheet_Change-event in my uploaded workbook and everything worked out fine (both in Excel2013 as well as in Excel2003) when Macros are activated. Please test if any single colour is added as I suspect you may have turned off events, or make clear that no other events in ThisWorkbook or behind the sheet are active.

    Ciao,
    Holger
    Last edited by HaHoBe; 03-29-2015 at 07:56 AM.

  17. #17
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    Hello holger.
    The new macro works almost fine.
    The problem is when you delete the letters.
    If you are in the white line the color remains, if they are in line blue color disappears.
    I'm trying on excel 2007.
    max_max
    --------------------------------------------------------------------------------------------
    Ciao holger.
    La nuova macro funziona quasi bene.
    Il problema è quando si cancellano le lettere.
    Se sono nella riga bianca il colore rimane, se sono nella riga azzurra il colore sparisce.
    Sto provando su excel 2007.
    max_max

    max_29_03.xls

  18. #18
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    there are 2 procedures (one of them coloring the area, one taking the job to colour/clear the selection). You used the procedure to colour down the whole area as one Worksheet_Change-event (never was planned to act as that) which produces exactly the "error" that you describe as the code only refers to filled cells (while the original Worksheet_Change-code handles areas which are altered).

    ColourLinesContents goes into a standard modul and is only used to colour in the values (this means just once!), Worksheet_Change goes behind the sheet.

    Ciao,
    Holger

  19. #19
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    Hello olger.
    Unfortunately I translate from Italian into English with google translator and this translates really bad.
    I hope you understand.
    In module1 there:

    Public Const cglngCOLOUR As Long = 34
    Sub ColourLines ()
    ,,
    ,,
    ,,

    in sheet1:

    Private Sub Worksheet_Change (ByVal Target As Range)
    Application.ScreenUpdating = False
    As Long Dim lngCtr
    As Range Dim rngCell
    ,,
    ,,
    ,,

    is that correct?
    max_max

  20. #20
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    exactrly like that, and you only run the code from Module1 once (you may change it a bit to take care of the additional colour which have not been taken away, I added that to the codelines). So the codes may look like
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    The first code is to get the area set up with the values inserted, the Worksheet_Change-event will take care of any changes in the area.

    Ciao,
    Holger

  21. #21
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    I entered as you wrote but does not change any color if I post a letter.
    max_max
    -------------------------------------------------------------------------------------
    Ho inserito come hai scritto ma non cambia nessun colore se inserisco una lettera.
    max_max

  22. #22
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: conditional formatting with vba

    Hi, max_max,

    I have no idea what you are doing to make a working code fail.

    Ciao,
    Holger
    Attached Files Attached Files

  23. #23
    Forum Contributor max_max's Avatar
    Join Date
    06-28-2013
    Location
    italy - venice
    MS-Off Ver
    Excel 2007
    Posts
    1,693

    Re: conditional formatting with vba

    Hello hahobe,
    after many tests I hold valid only this part:

    Please Login or Register  to view this content.
    works well.
    There are many sheets in the workbook all the same and you have to insert the macro in each sheet and workbook becomes too big so you have to put the macro in the ThisWorkbook.
    How can I change?
    I hope I explained beings.
    Thank you.
    xam_xam
    Last edited by max_max; 04-03-2015 at 01:38 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Formatting Cells with Date or Text Values in a Conditional Formatting Formula
    By Phil Hageman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-15-2014, 09:36 AM
  2. Opening xlsm files with conditional formatting opens with removed conditional formatting
    By Martijn.Steenbakker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2014, 05:38 AM
  3. Replies: 1
    Last Post: 09-20-2013, 06:23 PM
  4. Delete Conditional Formatting conditions but keep cell formatting - Excel 2010
    By tetreama in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2012, 08:28 PM
  5. Replies: 3
    Last Post: 05-15-2012, 04:13 PM

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