ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Number formate of Integer (https://www.excelbanter.com/excel-programming/364755-number-formate-integer.html)

Alf[_12_]

Number formate of Integer
 

Part of my macro looks like this:

Dim i As Integer

For i = Range("C2"). Value To Range("C3").Value Step 1

I've formated cells "C2" and "C3" so if I put 2 in "C2" and 10 in "C3"
it shows002 and 010.

When I run the macro i goes from 2 to 10 instead of 002 to 010.

I tried Range("C2").Value.NumberFormate = "000" This gives me a
Run-time error "424" : Object required

Gratefull for any hints to solve this problem.


--
Alf
------------------------------------------------------------------------
Alf's Profile: http://www.excelforum.com/member.php...fo&userid=7112
View this thread: http://www.excelforum.com/showthread...hreadid=553424


Gary''s Student

Number formate of Integer
 
The For loop will work as an integeror a long. If you want a special format
for i within the loop, then consider using the FORMAT() function.
--
Gary's Student


"Alf" wrote:


Part of my macro looks like this:

Dim i As Integer

For i = Range("C2"). Value To Range("C3").Value Step 1

I've formated cells "C2" and "C3" so if I put 2 in "C2" and 10 in "C3"
it shows002 and 010.

When I run the macro i goes from 2 to 10 instead of 002 to 010.

I tried Range("C2").Value.NumberFormate = "000" This gives me a
Run-time error "424" : Object required

Gratefull for any hints to solve this problem.


--
Alf
------------------------------------------------------------------------
Alf's Profile: http://www.excelforum.com/member.php...fo&userid=7112
View this thread: http://www.excelforum.com/showthread...hreadid=553424



Jim Thomlinson

Number formate of Integer
 
The statement you have is just a counter. It counts from the value of C2 to
the value of C3. It has nothing to do with the format of the cells. Try
adding these lines afterwards to see what I mean

msgbox i
msgbox format(i, "#,##0.00")
msgbox format(1, "0000")
--
HTH...

Jim Thomlinson


"Alf" wrote:


Part of my macro looks like this:

Dim i As Integer

For i = Range("C2"). Value To Range("C3").Value Step 1

I've formated cells "C2" and "C3" so if I put 2 in "C2" and 10 in "C3"
it shows002 and 010.

When I run the macro i goes from 2 to 10 instead of 002 to 010.

I tried Range("C2").Value.NumberFormate = "000" This gives me a
Run-time error "424" : Object required

Gratefull for any hints to solve this problem.


--
Alf
------------------------------------------------------------------------
Alf's Profile: http://www.excelforum.com/member.php...fo&userid=7112
View this thread: http://www.excelforum.com/showthread...hreadid=553424




All times are GMT +1. The time now is 04:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com