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.
Any help would be wonderful! Thanks in advance!
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!