LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 394
Default Calculate Last Digits

Hi everyone,

I am trying to loop through ALL the combinations and count the number
of occurances of the last digit for each of the combinations.
There are 10 categories of last digit :-

111111 2887500
211110 6930000
221100 2772000
222000 105600
311100 924000
321000 316800
330000 3960
411000 39600
420000 3960
510000 396
Total = 13983816

111111 means there are 2,887,500 combinations with all last digits
different.
321000 means there are 316,800 combinations where 3 of the last digits
are the same, 2 of the last digits are the same (but a different last
digit to the 3) and 1 last digit (but a different last digit to the 3
or 2).

Here is what I have so far :-

Option Explicit
Dim A As Long, B As Long, C As Long, D As Long, E As Long, F As Long

Sub LastDigit()
Dim i As Integer
Dim LastDigit As Integer
Dim DigitCounts(0 To 9) As Integer ' This will hold counters for each
digit 0-9
Dim nDupl As Integer
Const minVal As Integer = 1 ' The minimum value in ANY
combination
Const maxVal As Integer = 49 ' The maximum value in ANY
combination

Application.ScreenUpdating = False

For i = 0 To 9
DigitCounts(i) = 0
Next i

For A = minVal To maxVal - 5
For B = A + 1 To maxVal - 4
For C = B + 1 To maxVal - 3
For D = C + 1 To maxVal - 2
For E = D + 1 To maxVal - 1
For F = E + 1 To maxVal

For i = 0 To 4
LastDigit = i - 10 * Int(i) / 10
DigitCounts(LastDigit) = DigitCounts(LastDigit) + 1
Next i

nDupl = 0

For i = 0 To 9
If DigitCounts(i) 1 Then nDupl = nDupl +
DigitCounts(i)
Next i

Next F
Next E
Next D
Next C
Next B
Next A

ActiveCell.Offset(0, 5).Value = nDupl
ActiveCell.Offset(1, 0).Select

Application.ScreenUpdating = True
End Sub

Any help will be greatly appreciated.
Thanks in Advance.
All the Best.
Paul

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you change single digits to recognized double digits? Evil with a K[_2_] Excel Worksheet Functions 5 April 3rd 23 02:29 PM
VBA write macro change column with 3 number digits to 4 digits the James C[_2_] Excel Discussion (Misc queries) 3 January 25th 10 03:12 PM
What function do I use to calculate a Sum of Digits? NikL Excel Worksheet Functions 3 April 1st 09 07:46 PM
How to calculate the UPC Check Digits David Excel Worksheet Functions 4 May 24th 07 07:23 PM
calculate using last four digits of number in cell Andy Falkner Excel Worksheet Functions 3 February 10th 06 05:30 PM


All times are GMT +1. The time now is 11:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"