+ Reply to Thread
Results 1 to 17 of 17

vba not updating values

  1. #1
    Registered User
    Join Date
    04-17-2015
    Location
    Copenhagen
    MS-Off Ver
    2010
    Posts
    8

    Question vba not updating values

    Hello. I've found the following bit of code online, to add a =countccoolor function to excel, which counts the number of cells in a range that have a certain color. The range is the "A" column, and I color whole rows based on case status.

    Please Login or Register  to view this content.
    This lets me enter the following in cell A61: =countccolor(A$2:A59;B61)

    However, if I change the color of a cell (i.e. a whole row) in the range, the totals in the cells using the =countccolor function don't update. I have to click them and press f2 (or just double click them) and then enter, before the count changes. How can I make them update/run/execute/whatever it's called, whenever a I change a the formatting of a row?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,613

    Re: vba not updating values

    Mmmm, not sure you can. Colour is not data so changing the colour won't initiate a re-calculation. When you press F2 and Enter you are, effectively, changing a cell so Excel re-calculates.

    You might get away with pressing F9 to calculate

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: vba not updating values

    You can probably call the function on a Selection_Change event.. Coz Application.Volatile might not work because the sheet does not re-calculate when the color is applied..

    Selection_Change might be the only way I know where you will have to click somewhere else once for the code to get triggered...
    Cheers!
    Deep Dave

  4. #4
    Registered User
    Join Date
    04-17-2015
    Location
    Copenhagen
    MS-Off Ver
    2010
    Posts
    8

    Re: vba not updating values

    I will try that, since application.volatile didn't seem to work. Where in the code should I add the line?

  5. #5
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: vba not updating values

    Something like this

    Please Login or Register  to view this content.
    Be sure to put it on the right worksheet module.

    Also change the sheet name and range as required.

  6. #6
    Registered User
    Join Date
    04-17-2015
    Location
    Copenhagen
    MS-Off Ver
    2010
    Posts
    8

    Re: vba not updating values

    Thank you for your time and suggestions but it didn't work... I've made sure to enable events, restarted excel etc. Still no auto update :\

  7. #7
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: vba not updating values

    I would suggest using a different method to flag and count cells.
    Color (or any cell format) is just not a very effective means to flag cells for counting. It's not really data.

    What is the reason that a cell would be colored or not colored in the first place?
    Whatever criteria you use in your head to choose whether a cell is colored or not can probably be used as a criteria in a countif(s) type of function.

  8. #8
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: vba not updating values

    Quote Originally Posted by cgrubb View Post
    Thank you for your time and suggestions but it didn't work... I've made sure to enable events, restarted excel etc. Still no auto update :\
    Probably you are doing something wrong.. Works for me..

  9. #9
    Registered User
    Join Date
    04-17-2015
    Location
    Copenhagen
    MS-Off Ver
    2010
    Posts
    8

    Re: vba not updating values

    It worked!
    I reread the part about putting the code "on the right worksheet module" and after trying all permutations, found one that did the trick.
    Specifically, the code you suggested goes in the code list for the actual sheet and the code I posted goes in a module. Not immediately logical to me, but I think I understand it now.

    Thank you for you help!

  10. #10
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: vba not updating values

    I agree, I should have been more understandable with this

    on the right worksheet module
    Anyways, glad you got it working..

  11. #11
    Registered User
    Join Date
    04-17-2015
    Location
    Copenhagen
    MS-Off Ver
    2010
    Posts
    8

    Re: vba not updating values

    edit:

    This is a separate issue, so I'll mark this thread as solved and start a new one.
    Last edited by cgrubb; 10-08-2015 at 03:09 AM.

  12. #12
    Registered User
    Join Date
    01-21-2016
    Location
    South East
    MS-Off Ver
    2013
    Posts
    19

    Re: vba not updating values

    When adding in the
    HTML Code: 
    This may sound stupid, but which module do I put this in? Im having the same issue!

  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,360

    Re: vba not updating values

    I assume this should go in Sheet1.

    Right click on Sheet1 tab, "View Code" and past code into "white space".

  14. #14
    Registered User
    Join Date
    01-21-2016
    Location
    South East
    MS-Off Ver
    2013
    Posts
    19

    Re: vba not updating values

    Fantastic, thanks John.

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,360

    Re: vba not updating values

    Glad to help.

  16. #16
    Registered User
    Join Date
    02-16-2017
    Location
    Tampa, FL
    MS-Off Ver
    10
    Posts
    1

    Re: vba not updating values

    How can this been written to include more than one color? I have 3 colors, E1, E2, and E3, all on the same sheet.......how would it be written to include all 3? Thank you so much!
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Sheets("Sheet1").Calculate
    Call CountCcolor(Range("A1:A50"), Range("E1"))
    End Sub

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,613

    Re: vba not updating values

    Welcome to the forum.

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

+ 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. Replies: 0
    Last Post: 07-21-2015, 04:44 PM
  2. values not updating
    By 13lack13lade in forum Excel General
    Replies: 3
    Last Post: 04-16-2014, 01:21 AM
  3. Updating values without updating graphs
    By nj8988 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-21-2013, 07:57 PM
  4. List box values updating but text is not updating
    By Shane of the Newbs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-16-2011, 11:53 AM
  5. Updating values from import tab
    By madamson86 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2011, 05:10 AM
  6. Replies: 8
    Last Post: 11-22-2010, 01:20 PM
  7. Values not updating
    By Conan Kelly in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-14-2006, 07:45 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