Request = generate all formations from 000 to 999
In ascending order from smallest to largest.
Example =
234 = yes
459 = no
789 = yes
Another example = 889 = no, can not have digit repeat
The zero will be the smallest digit
Example = 023 = yes
Request = generate all formations from 000 to 999
In ascending order from smallest to largest.
Example =
234 = yes
459 = no
789 = yes
Another example = 889 = no, can not have digit repeat
The zero will be the smallest digit
Example = 023 = yes
This seems to work. *edited with code tags*
![]()
Please Login or Register to view this content.
This is not nearly enough information. You are going to have to give the rules for when a number is "yes" and when it is "no".
Your explanation is always rough and confusing....
![]()
Please Login or Register to view this content.
sorry =459= yes.
error=
Sub SomeRandomRequest()
The rules = generate the formations of increasing order where the 1st digit is the smaller the 2nd digit is the middle and the 3rd digit is the largest of all example =
269 = yes
962 = no
Oops. Try this. But jindon's impressive code will work as well.
![]()
Please Login or Register to view this content.
hello SPACE, error
Sub SomeRandomRequest()
Dim lngCounter As Long
Dim strFormations() As String
ReDim strFormations(0)
For lngCounter = 12 To 999 Step 1 'start at 12 - the first ascending number (012)
If IsAscending(CStr(lngCounter)) Then
![]()
Please Login or Register to view this content.
Is it necessary to use VBA? I would probably use a simple combination of =AND(), LEFT(), RIGHT(), MID(), and TEXT() functions (list of functions and help files: https://support.office.com/en-us/art...6-c6d90033e188 ).
TEXT(number,"000") will insure that the number is a text string with 3 digits (no error checking if someone enters a 4+ digit number)
LEFT(TEXT(number,"000"),1) will return the first digit.
MID(TEXT(number,"000"),2,1) will return the middle digit
RIGHT(TEXT(number,"000"),1) will return the last digit
AND(LEFT(...) < MID(...),MID(...) < RIGHT()) will return TRUE if the 3 digits are in increasing order and will return FALSE if not (assuming I thought through the logic all the way).
There are equivalent expressions in VBA (something like IsAscending() function), if it must be VBA.
Originally Posted by shg
Hello jindon, perfect, very good job, congratulations
Your response was the best, it's correct.
Jorel, was mine not correct because it didn't include the trailing zeros? Because my result is the same as Jindon's without those zeros.
Okay, SPACEit was said in the rules that zero was the smallest, and that it had to cover all the formations from 000 to 999
Jindon's answer was correct, yours is correct too.
It's just filtering,
Your work is also correct, thank you.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks