Delay in Generating Macro

amitkumar123

New Member
Joined
Jul 22, 2009
Messages
3
Hello ladies and gent <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I am a new user to excel and VBA, I have a slight little problem with excel coding. My aim was to generate colour from 20/25 different worksheets in one work book to show colour in a main worksheet. I have linked cells and used VBA code for extra conditional formats. <o:p></o:p>
<o:p> </o:p>
Problem<o:p></o:p>
<o:p> </o:p>
On the main worksheet the colour are generated with a macro selecting cells from other worksheet and spiting them on the main worksheet, but i am experiencing some major slowness every time I select generate button. It used to generate straight way and now is very slow and the screen keep on flickering. <o:p></o:p>
<o:p> </o:p>
I think it’s the VBA code which I got from a site and modified it:<o:p></o:p>
<o:p> </o:p>
Private Sub Worksheet_Change(ByVal Target As Range)<o:p></o:p>
<o:p></o:p>
Dim Cell As Range<o:p></o:p>
Dim Rng1 As Range<o:p></o:p>
<o:p></o:p>
On Error Resume Next<o:p></o:p>
Set Rng1 = ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, 1)<o:p></o:p>
On Error GoTo 0<o:p></o:p>
If Rng1 Is Nothing Then<o:p></o:p>
Set Rng1 = Range(Target.Address)<o:p></o:p>
Else<o:p></o:p>
Set Rng1 = <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:eek:ffice:smarttags" /><st1:place w:st="on">Union</st1:place>(Range(Target.Address), Rng1)<o:p></o:p>
End If<o:p></o:p>
For Each Cell In Rng1<o:p></o:p>
Select Case Cell.Value<o:p></o:p>
Case vbNullString<o:p></o:p>
Cell.Interior.ColorIndex = xlNone<o:p></o:p>
Cell.Font.Bold = False<o:p></o:p>
Case "Red: Serious issues exist"<o:p></o:p>
Cell.Interior.ColorIndex = 3<o:p></o:p>
Cell.Font.ColorIndex = 3<o:p></o:p>
Cell.Font.Bold = True<o:p></o:p>
Case "Green: No material issues"<o:p></o:p>
Cell.Interior.ColorIndex = 10<o:p></o:p>
Cell.Font.ColorIndex = 10<o:p></o:p>
Cell.Font.Bold = True<o:p></o:p>
Case "White: Not applicable"<o:p></o:p>
Cell.Interior.ColorIndex = 2<o:p></o:p>
Cell.Font.ColorIndex = 2<o:p></o:p>
Cell.Font.Bold = True<o:p></o:p>
Case "Amber: some material"<o:p></o:p>
Cell.Interior.ColorIndex = 45<o:p></o:p>
Cell.Font.ColorIndex = 45<o:p></o:p>
Cell.Font.Bold = True<o:p></o:p>
Case "Grey: Unable to form a view"<o:p></o:p>
Cell.Interior.ColorIndex = 15<o:p></o:p>
Cell.Font.ColorIndex = 15<o:p></o:p>
Cell.Font.Bold = True<o:p></o:p>
Case Else<o:p></o:p>
Cell.Interior.ColorIndex = xlNone<o:p></o:p>
Cell.Font.Bold = False<o:p></o:p>
End Select<o:p></o:p>
Next<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Could you expired kindly help me in this tough situation. <o:p></o:p>
<o:p> </o:p>
Amitkumar_52@hotmail.com <o:p></o:p>
<o:p> </o:p>
Kind Regards <o:p></o:p>
<o:p> </o:p>
A<o:p></o:p>
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hello and welcome to MrExcel.

Try turning off screen updating:

Code:
Dim Rng1 As Range
Application.ScreenUpdating = False
'
'
'
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi peter <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
What would be the full code to put into the page with the code that you just supplied? <o:p></o:p>

Kind Regard

Amit kumar
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
Dim Rng1 As Range
Application.ScreenUpdating = False
On Error Resume Next
Set Rng1 = ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, 1)
On Error GoTo 0
If Rng1 Is Nothing Then
    Set Rng1 = Range(Target.Address)
Else
    Set Rng1 = Union(Range(Target.Address), Rng1)
End If
For Each Cell In Rng1
    Select Case Cell.Value
        Case vbNullString
            Cell.Interior.ColorIndex = xlNone
            Cell.Font.Bold = False
        Case "Red: Serious issues exist"
            Cell.Interior.ColorIndex = 3
            Cell.Font.ColorIndex = 3
            Cell.Font.Bold = True
        Case "Green: No material issues"
            Cell.Interior.ColorIndex = 10
            Cell.Font.ColorIndex = 10
            Cell.Font.Bold = True
        Case "White: Not applicable"
            Cell.Interior.ColorIndex = 2
            Cell.Font.ColorIndex = 2
            Cell.Font.Bold = True
        Case "Amber: some material"
            Cell.Interior.ColorIndex = 45
            Cell.Font.ColorIndex = 45
            Cell.Font.Bold = True
        Case "Grey: Unable to form a view"
            Cell.Interior.ColorIndex = 15
            Cell.Font.ColorIndex = 15
            Cell.Font.Bold = True
        Case Else
                Cell.Interior.ColorIndex = xlNone
                Cell.Font.Bold = False
    End Select
Next
Application.ScreenUpdating = True
End Sub

Be aware that this code

Code:
            Cell.Interior.ColorIndex = 3
            Cell.Font.ColorIndex = 3
            Cell.Font.Bold = True

will render the text invisible as it sets both the fill colour and font colour to red.
 
Upvote 0

Forum statistics

Threads
1,215,398
Messages
6,124,688
Members
449,179
Latest member
kfhw720

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top