I created a BlinkCell effect using the code below
Sub BlinkCell(cel As Range)
' Capture the original cell formatting
Dim originalColor As Long
originalColor = cel.Interior.Color
Dim originalPattern As Long
originalPattern = cel.Interior.Pattern
' Blink the cell normally
Dim i As Integer
For i = 1 To 3
' Change the background color to white
cel.Interior.Color = RGB(255, 255, 255)
' Remove any existing pattern
cel.Interior.Pattern = xlNone
' Wait for 50 milliseconds
Sleep 50
' Restore the original background color
cel.Interior.Color = originalColor
' Restore the original pattern
cel.Interior.Pattern = originalPattern
' Wait for 50 milliseconds
Sleep 50
Next i
End Sub
It works fine – become white and try to restore the original color and pattern – but don’t restore the original colors on cell that contains fill patterns – they become blue instead it
How to fill the cell with the original colors and patterns instead of become blue?
I tried:
Sub BlinkCell(cel As Range)
' Capture the original cell formatting
Dim originalColor As Long
Dim hasFill As Boolean
hasFill = CBool(cel.HasFill)
If hasFill Then
originalFill = cel.Fill.PatternStyle
Else
' How to fill the cell with the original colors and patterns instead of become blue?
originalColor = cel.Interior.Color
End If
' Blink the cell normally
Dim i As Integer
For i = 1 To 3
If hasFill Then
cel.Fill.PatternStyle = xlPatternNone ' Set fill to none
Else
cel.Interior.Color = RGB(255, 255, 255) ' Change background to white
End If
Sleep 50 ' Wait for 50 milliseconds
If hasFill Then
cel.Fill.PatternStyle = originalFill ' Restore original fill pattern
Else
cel.Interior.Color = originalColor ' Restore original background color
End If
Sleep 50 ' Wait for 50 milliseconds
Next i
End Sub
The code results in the following error:
Object doesnt support this property or method
on originalFill = cel.Fill.PatternStyle
Pamn Labs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.