VBA, list of number which after divided with x value results whole number

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,

I want a "list of numbers" which after divided with x value results whole number

Please for example see the sample image. In the column C I have entered value 211876 which I tried to divided with the numbers are in the column formula in D3 =C3/B3 copied down. Some result of the division is in decimals and others in whole number.

But I need a "list of number" which after divided with x value results whole number as shown in the columns G:H, list of numbers gives after division gives whole number are 1, 2, 4, 14, 23, 28, 46 47, 49, 92, 98... and continue....

Basically I need a macro, which can ask...
1st-input X value, in this given example x value is = 211876
2nd-divisor starting number, in this given example divisor starting value is = 1
After entering both vales display the result list as shown in the column G: H


*ABCDEFGHIJ
1Formula D3=C3/B3
2NumberValueWhole NumberNumberValueWhole Number
312118762118761211876211876
422118761059382211876105938
5321187670625,33333421187652969
64211876529691421187615134
7521187642375,2232118769212
8621187635312,66667282118767567
9721187630268462118764606
10821187626484,5472118764508
11921187623541,77778492118764324
121021187621187,6922118762303
131121187619261,45455982118762162
141221187617656,33333
151321187616298,15385
161421187615134
171521187614125,06667
181621187613242,25
191721187612463,29412
201821187611770,88889
211921187611151,36842
222021187610593,8
232121187610089,33333
24222118769630,727273
25232118769212
26242118768828,166667
27252118768475,04
28262118768149,076923
29272118767847,259259
30282118767567
31292118767306,068966
32302118767062,533333
33312118766834,709677
34322118766621,125
35332118766420,484848
36342118766231,647059
37352118766053,6
38362118765885,444444
39372118765726,378378
40382118765575,684211
41392118765432,717949
42402118765296,9
43412118765167,707317
44422118765044,666667
45432118764927,348837
46442118764815,363636
47452118764708,355556
48462118764606
49472118764508
50482118764414,083333
51492118764324
52502118764237,52
53512118764154,431373
54522118764074,538462
55532118763997,660377
56542118763923,62963
57552118763852,290909
58562118763783,5
59572118763717,122807
60582118763653,034483
61592118763591,118644
62602118763531,266667
63612118763473,377049
64622118763417,354839
65632118763363,111111
66642118763310,5625
67652118763259,630769
68662118763210,242424
69672118763162,328358
70682118763115,823529
71692118763070,666667
72702118763026,8
73712118762984,169014
74722118762942,722222
75732118762902,410959
76742118762863,189189
77752118762825,013333
78762118762787,842105
79772118762751,636364
80782118762716,358974
81792118762681,974684
82802118762648,45
83812118762615,753086
84822118762583,853659
85832118762552,722892
86842118762522,333333
87852118762492,658824
88862118762463,674419
89872118762435,356322
90882118762407,681818
91892118762380,629213
92902118762354,177778
93912118762328,307692
94922118762303
95932118762278,236559
96942118762254
97952118762230,273684
98962118762207,041667
99972118762184,28866
100982118762162
101992118762140,161616
1021002118762118,76
103
104

Thank you all.

I am using Excel 2000

Regards,
Moti
 

Attachments

  • List Whole Number.png
    List Whole Number.png
    108.4 KB · Views: 10

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Why not? It's part of the code & they need to be entered.
That would be considered a 'constant' value, theoretically, so why time it? If all versions of the code are asking for the two values to begin with, why time it? It is asking for timing discrepencies due to the speed of the user entering the values, not necessarily the speed of the code functioning.

In theory I could start the code, enter the first value, go make a cup of coffee, come back and enter the second value. Is that a fair testing of the timing of the code? Like I said if you include the entering of the values to be used, you are asking for skewed results.
 
Upvote 0
In theory I could start the code, enter the first value, go make a cup of coffee, come back and enter the second value. Is that a fair testing of the timing of the code?
IMO Yes, because that's how long it took the code to run.
 
Upvote 0
If the code is not executing any code after it has asked the user for a response, is that considered code running?
 
Upvote 0
You should not include the time it takes to enter the starting values.

The following runs the code 5 times in under a second.

Try the following:

VBA Code:
Sub FindWholeNumbersTimed()
'
    Dim DivisorIncrementer  As Long
    Dim RowCounter          As Long
    Dim StartingDivisor     As Long
    Dim Xvalue              As Long
    Dim TimedTrials As Long
'
    RowCounter = 3
'
    Xvalue = Application.InputBox("What is the X value?", "Whole Number Finder", Type:=1)
    If Xvalue = 0 Then Exit Sub
'
    StartingDivisor = Application.InputBox("What is the Divisor number to start with?", "Whole Number Finder", Type:=1)
    If StartingDivisor = 0 Then Exit Sub
'
    Range("J2:N2").Delete Shift:=xlUp                                                                   ' Delete any previously timed values
'
    For TimedTrials = 1 To 5
        Start = Timer
'
        For DivisorIncrementer = StartingDivisor To Xvalue
            If Xvalue Mod DivisorIncrementer = 0 Then
                Range("G" & RowCounter) = DivisorIncrementer
                Range("H" & RowCounter) = Xvalue
                Range("I" & RowCounter) = Xvalue / DivisorIncrementer
                RowCounter = RowCounter + 1
            End If
        Next
        Cells(2, TimedTrials + 9) = Timer - Start
        TotalRunTime = TotalRunTime + Cells(2, TimedTrials + 9)
    Next
'
    Range("P2") = TotalRunTime / 5
'
    MsgBox "Done Calculating"
End Sub


Book1
ABCDEFGHIJKLMNOP
1Time Trial 1Time Trial 2Time Trial 3Time Trial 4Time Trial 5Average Time in seconds
2NumberValueWhole #0.19531250.14843750.152343750.152343750.156250.1609375
3150000005000000
4250000002500000
5450000001250000
6550000001000000
785000000625000
8105000000500000
9165000000312500
10205000000250000
11255000000200000
12325000000156250
13405000000125000
14505000000100000
1564500000078125
1680500000062500
17100500000050000
18125500000040000
19160500000031250
20200500000025000
21250500000020000
22320500000015625
23400500000012500
24500500000010000
2562550000008000
2680050000006250
27100050000005000
28125050000004000
29160050000003125
30200050000002500
31250050000002000
32312550000001600
33400050000001250
34500050000001000
3562505000000800
3680005000000625
37100005000000500
38125005000000400
39156255000000320
40200005000000250
41250005000000200
42312505000000160
43400005000000125
44500005000000100
4562500500000080
4678125500000064
47100000500000050
48125000500000040
49156250500000032
50200000500000025
51250000500000020
52312500500000016
53500000500000010
5462500050000008
55100000050000005
56125000050000004
57250000050000002
58500000050000001
Sheet1
johnnyL, Today I learn one new lesson how to check timer your code truly runs 5 times runs less the 1 second.

Really thank you so much for all your contribution, (y)

Good Luck to you

Kind Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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