.ClearContents Redirects to Function

szymagic

Board Regular
Joined
Jul 8, 2016
Messages
61
Hi Everyone,

So every time a line of code with .ClearContents is ran, the macro redirects to a Function, and then the function runs through a seemingly infinite loop (I don't have the patience to manually debug through it) which really slows down my macro since there are quite a few lines of code that contain .ClearContents

Here is the first bit of the code I'm trying to run, and then the next is the function code.

Code:
Application.ScreenUpdating = False
' GetReport Macro
' Retrieve the Report

'Reset
    Sheets("Priority&Weights").Activate
    Range("A2:A250").ClearContents 'after this line it redirects
    Sheets("Report").Activate
    Range("Table1").Select

Code:
Function nMax(Rng As Range) As Double
Dim Dn As Range, n As Long, K As Variant, oMax As Double
Dim Dic As Object
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
For Each Dn In Rng
    If Not Dic.Exists(Dn.Value) Then
        Dic.Add Dn.Value, Dn.Offset(, -12)
    Else
        Set Dic.Item(Dn.Value) = Union(Dic.Item(Dn.Value), Dn.Offset(, -12))
    End If
Next
For Each K In Dic.keys
    With Application
      If .Sum(Dic.Item(K)) > oMax Then
            oMax = .Sum(Dic.Item(K))
            nMax = K
        End If
    End With
Next K
End Function


Any help would be wonderful! Thanks in advance!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Disable calculation at the start of the macro and then re-enable it at the end.
 
Upvote 0
Disable calculation at the start of the macro and then re-enable it at the end.

Thanks RoryA! Works like a charm! But now my whole process doesn't work haha. What my macro does is grab calculated lines of data and pastes them in a report.. So now I just have a bunch of DIV/0 errors.

Am I just going to have to live with the slow macro?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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