Re: Calculate Last Digits

Tech-Archive recommends: Fix windows errors by optimizing your registry



See possible code improvement, in-line:

Private Sub UpdateCounts()
Dim Cnt(0 To 9) As Long
Dim n As Long
Dim j As Long
Dim max As Long
Dim pattern As String

For n = 1 To 6
Cnt(LastDigits(n)) = Cnt(LastDigits(n)) + 1
Next n

For n = 1 To 6
max = 0
For j = 0 To 9
If Cnt(j) > Cnt(max) Then
max = j
End If

This might work faster by adding the following line at this point:

If Cnt(j) >= 3 Then Exit For

(Or use whatever method you prefer to exit the For Loop...personally I avoid Exit For, as discussed at enormous length in older
threads <g>, but this is the easiest change given the existing code.) This works because you KNOW if your count is greater than or
equal to 3, there won't be anything higher, and you can add it to the string right away. On the other hand, the extra comparison
may end up slowing things down more than it speeds them up. Try it both ways and see.

Next j
pattern = pattern & Cnt(max)
Cnt(max) = 0
Next n

For n = 1 To UBound(Map)
If Map(n) = pattern Then
Counts(n) = Counts(n) + 1
Exit For
End If
Next n

End Sub


Rob


.



Relevant Pages

  • Re: find last part of text
    ... Function RegexMid(Str As String, Pattern As String, _ ... Dim objRegExp As Object ... 'Set the pattern by using the Pattern property. ... Set colMatches = objRegExp.Execute' Execute search. ...
    (microsoft.public.excel)
  • Re: parse cell contents
    ... extract the date I will get the yyyy-mm-dd format. ... What we will do is first look at the first word in the string. ... Dim ValidEntry As Boolean ... 'Set the pattern by using the Pattern property. ...
    (microsoft.public.excel.programming)
  • Re: How in to parse constants in formula to cells
    ... Dim X As String, Z As String ... Dim Y As Variant, Signs As Variant ... Dim Pattern As String ...
    (microsoft.public.excel.programming)
  • Re: Selection of text from a string
    ... For more information regarding the syntax for the Pattern argument, ... Function RegexMid(Str As String, Pattern As String, _ ... Dim objRegExp As Object ... RegexMid = T ...
    (microsoft.public.excel.programming)
  • Re: macro for parsing text
    ... SUB will remove from any cell selected the pattern as you described (i.e. ... Dim c As Range ... Dim Temp As String ... Dim colMatches As MatchCollection ...
    (microsoft.public.excel.programming)