Worksheet running slow; is there a contradiction in my macro?

men5j2s

Board Regular
Joined
Apr 26, 2016
Messages
59
Office Version
  1. 365
Platform
  1. Windows
Hi,

This would be easier if I could share the workbook, but I have a particular sheet that doesn't have any data in it whatoever and it is running so slow that its not functional.

The intent is for data to be in there, but I am just optimising the entire workbook (ironically).

Does any of the following code look problematic? first is the worksheet code and then the workbook code.

thank you in advance.

Worksheet Code ("DataBase!"):

Code:
Private Sub Worksheet_Activate()
    Range("A1:H1").Select
    ActiveWindow.Zoom = True
Range("A" & Rows.Count).End(xlUp).Select
End Sub






Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Dim cTop As Long
Dim cWidth As Long
Dim cmt As Comment
Dim Sh As Shape



Application.DisplayCommentIndicator _
= xlcommentIndicator0nly


Set rng = ActiveWindow.VisibleRange
cTop = rng.Top + rng.Height / 2
cWidth = rng.Left + rng.Width / 2


If ActiveCell.Comment Is Nothing Then
'do nothing
Else
Set cmt = ActiveCell.Comment
Set Sh = cmt.Shape
Sh.Top = cTop - Sh.Height / 2
Sh.Left = cWidth - Sh.Width / 2
cmt.Visible = True
End If




End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("D:D")) Is Nothing Then
        colourDates Intersect(Target, Range("D:D")).Cells
    End If
End Sub

workbook Code:



Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)


Sheets("Warning").Visible = True


Sheets("SalesLog").Visible = xlVeryHidden
Sheets("Orders").Visible = xlVeryHidden
Sheets("Reporting").Visible = xlVeryHidden
Sheets("Settings").Visible = xlVeryHidden
Sheets("DataBase").Visible = xlVeryHidden
Sheets("Trends").Visible = xlVeryHidden
Sheets("Compare").Visible = xlVeryHidden
Sheets("Trend Data").Visible = xlVeryHidden
Sheets("Client File").Visible = xlVeryHidden


End Sub




Private Sub Workbook_Open()
    Dim lastRow               As Long
    Sheets("SalesLog").Visible = True
    Sheets("Orders").Visible = True
    Sheets("Reporting").Visible = True
    Sheets("Settings").Visible = xlHidden
    Sheets("DataBase").Visible = True
    Sheets("Trends").Visible = True
    Sheets("Compare").Visible = True
    Sheets("Trend Data").Visible = xlHidden
    Sheets("Client File").Visible = True


    Sheets("Reporting").Activate




    Sheets("Warning").Visible = xlVeryHidden
    With Sheets("Database")
        If .AutoFilterMode Then
            If .FilterMode Then .ShowAllData
        End If
        lastRow = .Cells(.Rows.Count, "D").End(xlUp).row
        colourDates .Range("D5:D" & lastRow)
    End With
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
UPDATE...

The problematic code is this bit...

Code:
'Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Dim rng As Range
'Dim cTop As Long
'Dim cWidth As Long
'Dim cmt As Comment
'Dim Sh As Shape


'Application.DisplayCommentIndicator _
'= xlcommentIndicator0nly


'Set rng = ActiveWindow.VisibleRange
'cTop = rng.Top + rng.Height / 2
'cWidth = rng.Left + rng.Width / 2


'If ActiveCell.Comment Is Nothing Then
'do nothing
'Else
'Set cmt = ActiveCell.Comment
'Set Sh = cmt.Shape
'Sh.Top = cTop - Sh.Height / 2
'Sh.Left = cWidth - Sh.Width / 2
'cmt.Visible = True
'End If




'End Sub

Ive put inverted commas in to disable it and it works fine..

can anyone tell me why? this specific part is quite old and is actually working fine in a database will hundreds of entries, its quite an important part of the whole project too.

thanks
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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