# Right Function In VBA To Count the Zero's

• Good day my friends,

I have a rather interesting problem I have not been able to sort. I have a line of code that extracts the last two digits of a certain cell and places them in the cell next to it. However, if the last two digits are Zeros it only returns the first whole number in the cell.

This is what I have...

Code
Sheet1.Range("H21").Value = "0." & Right(Cells(21, 11), 2)

If my cells value is 6.00 it returns 0.60 now matter how I change the format or the VBA code.

Note...
In order for everything else to work... the "0." in my code must remain as it is part of a Vlookup.

Cheers

[SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

• Re: Right Function In VBA To Count the Zero's

Code
Sheet1.Range("H21").Value = "0." & Right(Cells(21, 11).text , 2)

format the cell as number with 2 decimals.

• Re: Right Function In VBA To Count the Zero's

I am a little embarrassed I must say lol. That seems to have done the trick jindon. Thanks so much

[SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

• Re: Right Function In VBA To Count the Zero's

Code
With Sheet1
If .Cells(21, 11) - Int(.Cells(21, 11)) = 0 Then
.Range("H21") = 0
Else
.Range("H21") = "0." & Right(.Cells(21, 11), 2)
End If
End With

[FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
Tip: To avoid chasing code always use Option Explicit.

• Re: Right Function In VBA To Count the Zero's

jindon better solution

[FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
Tip: To avoid chasing code always use Option Explicit.

• Re: Right Function In VBA To Count the Zero's

Thanks for taking the time to work out another solution Mr Bill

[SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

• Re: Right Function In VBA To Count the Zero's

Quote from Bill Rockenbach;666428

jindon better solution

Thanks, but the column width of the cell should be wide enough to show whole numbers when .text property is used.
When the cell shows "########", it picks up exactly what it shows....

## Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!