Results 1 to 9 of 9

Thread: Code to make cell flash in Excel needed :RESOLVED

  1. #1

    Thread Starter
    New Member Excel Guru's Avatar
    Join Date
    Feb 2005
    Location
    So Cal
    Posts
    3

    Resolved Code to make cell flash in Excel needed :RESOLVED

    Hello all! I am new to VBforum and need some help. I am a newbee with VBA and VB. I need some help with some code. I want to make the background of a specific cell i.e. G39 Flash red, when the value entered is below a established amount specified in E39. I just need something I can build on. Any help would greatly be appreciated. Thanks
    Last edited by Excel Guru; Mar 1st, 2005 at 09:21 PM. Reason: Resolved

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Code to make cell flash in Excel needed

    Welcome to the Forums Excel Guru!

    Do you need it to flash or just change the background color? This will just
    change the background color to red if the value entered in E39 is less then
    100.

    VB Code:
    1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    2.     If Range("E39").Value < 100 Then
    3.         With Range("G39").Interior
    4.             .ColorIndex = 3
    5.             .Pattern = xlSolid
    6.             .PatternColorIndex = xlAutomatic
    7.         End With
    8.     Else
    9.         With Range("G39").Interior
    10.             .ColorIndex = 0
    11.             .Pattern = xlSolid
    12.             .PatternColorIndex = xlAutomatic
    13.         End With
    14.     End If
    15. End Sub
    VB/Office Guru™

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Code to make cell flash in Excel needed

    Here is better code that fixes the border coloring issue. Place this behind Sheet1 for ex.
    or we can change the code to run from a module on all sheets.

    VB Code:
    1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    2.     If Range("E39").Value < 100 Then
    3.         With Range("G39").Interior
    4.             .ColorIndex = 3
    5.             .Pattern = xlSolid
    6.             .PatternColorIndex = xlAutomatic
    7.         End With
    8.     Else
    9.         With Range("G39")
    10.             .Interior.ColorIndex = 0
    11.             .Interior.Pattern = xlSolid
    12.             .Interior.PatternColorIndex = xlAutomatic
    13.             .Borders(xlDiagonalDown).LineStyle = xlNone
    14.             .Borders(xlDiagonalUp).LineStyle = xlNone
    15.             .Borders(xlEdgeLeft).LineStyle = xlNone
    16.             .Borders(xlEdgeTop).LineStyle = xlNone
    17.             .Borders(xlEdgeBottom).LineStyle = xlNone
    18.             .Borders(xlEdgeRight).LineStyle = xlNone
    19.             .Interior.ColorIndex = xlNone
    20.         End With
    21.     End If
    22. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    New Member Excel Guru's Avatar
    Join Date
    Feb 2005
    Location
    So Cal
    Posts
    3

    Re: Code to make cell flash in Excel needed

    Thanks RobDog888. The first example worked good but can I get it to flash? Your help is greatly appreciated and thanks for the quick response.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Code to make cell flash in Excel needed

    I suppose so.

    Insert paycheck here -->

    How long do you want it to continue flashing?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Code to make cell flash in Excel needed

    This will make it flash for 30 seconds with an interval of 500 miliseconds.
    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    2.  
    3. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    4.     Dim Start
    5.     Dim FlashDuration
    6.     FlashDuration = 30000 '30 seconds
    7.     If Range("E39").Value < 100 Then
    8.         Start = Timer    ' Set start time.
    9.         Do While Timer < Start + FlashDuration
    10.             DoEvents    ' Yield to other processes.
    11.             Sleep 500
    12.             FlashMe
    13.         Loop
    14.         With Range("G39").Interior
    15.             .ColorIndex = 3
    16.             .Pattern = xlSolid
    17.             .PatternColorIndex = xlAutomatic
    18.         End With
    19.     Else
    20.         With Range("G39")
    21.             .Interior.ColorIndex = 0
    22.             .Interior.Pattern = xlSolid
    23.             .Interior.PatternColorIndex = xlAutomatic
    24.             .Borders(xlDiagonalDown).LineStyle = xlNone
    25.             .Borders(xlDiagonalUp).LineStyle = xlNone
    26.             .Borders(xlEdgeLeft).LineStyle = xlNone
    27.             .Borders(xlEdgeTop).LineStyle = xlNone
    28.             .Borders(xlEdgeBottom).LineStyle = xlNone
    29.             .Borders(xlEdgeRight).LineStyle = xlNone
    30.             .Interior.ColorIndex = xlNone
    31.         End With
    32.     End If
    33. End Sub
    34.  
    35. Private Sub FlashMe()
    36.     Static bOn As Boolean
    37.     If bOn = True Then
    38.         bOn = False
    39.         With Range("G39")
    40.             .Interior.ColorIndex = 0
    41.             .Interior.Pattern = xlSolid
    42.             .Interior.PatternColorIndex = xlAutomatic
    43.             .Borders(xlDiagonalDown).LineStyle = xlNone
    44.             .Borders(xlDiagonalUp).LineStyle = xlNone
    45.             .Borders(xlEdgeLeft).LineStyle = xlNone
    46.             .Borders(xlEdgeTop).LineStyle = xlNone
    47.             .Borders(xlEdgeBottom).LineStyle = xlNone
    48.             .Borders(xlEdgeRight).LineStyle = xlNone
    49.             .Interior.ColorIndex = xlNone
    50.         End With
    51.     Else
    52.         bOn = True
    53.         With Range("G39").Interior
    54.             .ColorIndex = 3
    55.             .Pattern = xlSolid
    56.             .PatternColorIndex = xlAutomatic
    57.         End With
    58.     End If
    59. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member Excel Guru's Avatar
    Join Date
    Feb 2005
    Location
    So Cal
    Posts
    3

    Resolved Re: Code to make cell flash in Excel needed :RESOLVED

    Thanks again RobDog888. Just what I needed Thanks for taking the time to answer my post in a timely manner and with a quick and accurate response. You are a true GURU

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Code to make cell flash in Excel needed :RESOLVED

    Here are your new changes you asked about.
    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    2.  
    3. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    4.     Dim Start
    5.     Dim FlashDuration
    6.     FlashDuration = 15 '30 seconds
    7.     If Range("E39").Value > Range("G39").Value Then
    8.         Start = Timer    ' Set start time.
    9.         Do While Timer < Start + FlashDuration
    10.             DoEvents    ' Yield to other processes.
    11.             Sleep 250
    12.             FlashMe
    13.         Loop
    14.         With Range("G39").Interior
    15.             .ColorIndex = 3
    16.             .Pattern = xlSolid
    17.             .PatternColorIndex = xlAutomatic
    18.         End With
    19.     Else
    20.         With Range("G39")
    21.             .Interior.ColorIndex = 10
    22.             .Interior.Pattern = xlSolid
    23.             .Interior.PatternColorIndex = 10 'xlAutomatic
    24.             .Borders(xlDiagonalDown).LineStyle = xlNone
    25.             .Borders(xlDiagonalUp).LineStyle = xlNone
    26.             .Borders(xlEdgeLeft).LineStyle = xlNone
    27.             .Borders(xlEdgeTop).LineStyle = xlNone
    28.             .Borders(xlEdgeBottom).LineStyle = xlNone
    29.             .Borders(xlEdgeRight).LineStyle = xlNone
    30.             .Borders.ColorIndex = 10
    31.         End With
    32.     End If
    33. End Sub
    34.  
    35. Private Sub FlashMe()
    36.     Static bOn As Boolean
    37.     If bOn = True Then
    38.         bOn = False
    39.         With Range("G39")
    40.             .Interior.ColorIndex = 0
    41.             .Interior.Pattern = xlSolid
    42.             .Interior.PatternColorIndex = xlAutomatic
    43.             .Borders(xlDiagonalDown).LineStyle = xlNone
    44.             .Borders(xlDiagonalUp).LineStyle = xlNone
    45.             .Borders(xlEdgeLeft).LineStyle = xlNone
    46.             .Borders(xlEdgeTop).LineStyle = xlNone
    47.             .Borders(xlEdgeBottom).LineStyle = xlNone
    48.             .Borders(xlEdgeRight).LineStyle = xlNone
    49.             .Interior.ColorIndex = xlNone
    50.         End With
    51.     Else
    52.         bOn = True
    53.         With Range("G39").Interior
    54.             .ColorIndex = 3
    55.             .Pattern = xlSolid
    56.             .PatternColorIndex = xlAutomatic
    57.         End With
    58.     End If
    59. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    New Member
    Join Date
    May 2008
    Posts
    1

    Re: Code to make cell flash in Excel needed :RESOLVED

    Dear Sir/Madam,
    I need to flash a cell for example if cell C36 greater than 100 with red/pink color and if C36 is less or equal 100 ,the cell flash yellow/orange color.
    May u help me?

Posting Permissions

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



Click Here to Expand Forum to Full Width