+ Reply to Thread
Results 1 to 2 of 2

Thread: Application.volatile not working

  1. #1
    Forum Contributor
    Join Date
    07-15-2011
    Location
    Whitby, Canada
    MS-Off Ver
    Excel 2010
    Posts
    121

    Application.volatile not working

    Hi all,

    I have a piece of code in a workbook (module 2) to change the colour of certain text when selected from a drop down list. Sometimes the colour changes, sometimes it doesn't it seems pretty random. I want the colour to change as soon as it's selected, I don't want to have to run the macro manually Here is the code:

    Sub OTcolour()
    Application.Volatile True
    
    ActiveSheet.Unprotect Password:="fire"
        Dim Values As Range
        Dim cell As Variant
        Set Values = Range("A3:F28")
        For Each cell In Values
            If cell.Value = "OT" Or cell.Value = "A/P/C" Or cell.Value = "A/C" Or cell.Value = "DE-IN" _
            Or cell.Value = "DE-IN AC" Or cell.Value = "DE-IN APC" Or cell.Value = "OT-AC" Or cell.Value = "OT-APC" Then
                cell.Font.ColorIndex = 10
                    End If
                    Next cell
    ActiveSheet.Protect Password:="fire", userinterfaceonly:=True
    End Sub
    So, if I select "OT" in cell B6, the colour changes - great...but if I select "OT" in cell B10 - nothing. Not sure where I've gone wrong but any help would be appreciated. Workbook attached
    TIA
    Attached Files Attached Files

  2. #2
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: Application.volatile not working

    Application.Volatile is used to make a user-defined function recalculate any time the Excel application calculates -- it's not relevant to a sub.

    You'd need to call the sub from the Calculate event.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Application.volatile not working

    You could add this to your Change event code after the last End If
        Dim Values As Range
        Dim cell As Variant
        Set Values = Range("A3:F28")
        If not intersect(target, values) is nothing then
    Me.Unprotect Password:="fire"
        For Each cell In intersect(target, values)
            Select Case cell.Value
                Case "OT", "A/P/C", "A/C", "DE-IN", "DE-IN AC", "DE-IN APC", "OT-AC", "OT-APC"
                    cell.Font.ColorIndex = 10
                End Select
        Next cell
    
    Me.Protect Password:="fire", userinterfaceonly:=True
    End If
    (untested)
    Good luck.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0