Modification of VBA to use scripting dictionary instead of Evaluate(Formula)

I had this question after viewing How to get the same result given by formula vba Scripting Dictionary?.


Rgonzo1971 was so kind helping me, wrapping the formula into Evaluate method to output the result in a cell.

i used debug.print timer in the begging of my code and at the end, for many formulas like this. it takes quite a lot of time.

i was wondering if there is any easy solution with scripting dictionary to extract the same result but not using the formula.

if it is not possible or takes too much time, then i can live with this, otherwise if it is possible for scripting dictionary then it will really make the code faster.   for just one formula, i can replicate for my other formulas. all i need is just for this one formula.

I am not good at coding, but i found use of scripting dictinary very effective and fast.
for example,  VBA to remove duplicate with formula was too slow and with scripting dictionary was many time faster than formula method.

thanks very much for your help.
EE.xlsb
LVL 6
FloraAsked:
Who is Participating?
 
Rgonzo1971Connect With a Mentor Commented:
Hi,

then try
Sub macro1()
For Each c In Range(Sheets("Data").Range("a2"), Sheets("Data").Range("a" & Rows.Count).End(xlUp))
    If (c.Value = 2011 Or c.Value = 2012) And c.Offset(, 1).Value <> 111 And _
            (c.Offset(, 2).Value Like "5*" Or c.Offset(, 2).Value Like "6*" Or c.Offset(, 2).Value Like "7*") Then
        mySum = mySum + c.Offset(, 3).Value
    End If
Next
Sheets("Main").Range("B5") = mySum
End Sub

Open in new window


EDIT Dictionary is perfect to create a list of unique values not in this case

Regards
1
 
FloraAuthor Commented:
Many thanks
0
 
Rgonzo1971Commented:
shorter
Sub macro1()
For Each c In Range(Sheets("Data").Range("a2"), Sheets("Data").Range("a" & Rows.Count).End(xlUp))
    If (c.Value = 2011 Or c.Value = 2012) And c.Offset(, 1).Value <> 111 And _
            (c.Offset(, 2).Value Like "[5-7]*") Then
        mySum = mySum + c.Offset(, 3).Value
    End If
Next
Sheets("Main").Range("B5") = mySum
End Sub

Open in new window

1
 
FloraAuthor Commented:
many thanks Rgonzo1971
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.