View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Format of Variable

Dim v as String
' if the cell Enter_RefNo is displaying 0001 then

v= Range("Enter_RefNo").Text

or
' if it displays 1
v = format(Range("Enter_RefNo").Value,"0000")

or with v containing "1" or 1

v = format(clng(v),"0000")

or

v = Right(v & "0000",4)


--
Regards,
Tom Ogilvy


"Andibevan" wrote in message
...
Sorry Tom, I wasn't clear enough - I am using the value Enter_RefNo in a
piece of VBA code and need the number format to remain as 0000 in the

code.

I.e. if I put 0001 into Enter_RefNo, currently that gets picked up as "1"
whereas I need it to be formatted as "0001" in order to get a match later

in
the code.

Thanks

Andi

"Tom Ogilvy" wrote in message
...
Range("Enter_RefNo").NumberFormat = "0000"

--
Regards,
Tom Ogilvy

"Andibevan" wrote in

message
...
Hi All,

I have a cell with a named range Enter_RefNo

I want to format this variable in the format as follow

1 -- 0001
10 -- 0010
11 -- 0011

And so on

Any ideas?

Regards

Andi