Home excel VBA Excel - check for zero digits before and after certain digits...

# VBA Excel – check for zero digits before and after certain digits of a number

Author

Date

Category

Take a number in the range from 1 to 1 000 000 000 000 000, where the class of digits of the number that we will check is highlighted in bold for example. It is necessary to check the condition under which the classes before it (thousands and ones) are empty. Separately, it is necessary to check the condition under which the classes after the selected one are empty (billions, trillions and quadrillions). If the first condition is true and the second is not, the result must be true, otherwise false. The problem is that I can’t make a loop of this code for all classes of digits.
We divided the number into classes like this:

``````For i1 = 1 To 6 'i1 - number of the bit class from right to left
x = Fix (x) / 1000 'x - original number
y (i1) = (x - Fix (x)) * 1000 'y (i1) - a group of numbers in each class
Next
``````

The classes were divided into categories like this:

``````For i2 = 1 To 6 'i2 - bit class number from right to left
y1 = y (i2) Mod 10 'y1 - digit of the place of hundreds of each class
y2 = (y (i2) - y1) / 10 Mod 10 'y2 - the digit of the tens of each class
y3 = y (i2) \ 100 'y3 - digit of the place of units of each class
Next
``````

For example, the number 1 235 000 687 000 000 should look like this:

fffttt

Using the number 225 485 as an example:

ffffft

For example, the number 200,000:

ffffft

etc.

``````Sub test ()
Const x As Double = 1234567
Debug.Print fCheckClasses (x)
End Sub
Function fCheckClasses (x As Double) As String
Dim i As Long
For i = 3 To Len (x & amp; "") Step 3
If Int (x Mod 10 ^ i) & gt; 0 Then Exit For
Next i
If i & gt; = Len (x & amp; "") Then i = i - 3
i = i / 3
fCheckClasses = Left \$ ("ffffff", 6 - i) & amp; Left \$ ("ttttt", i)
End Function
``````

Maybe the definition of `i `is enough and there is no need to draw `String `?

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.