vba format question

D

David

cells(1).value = 3
With code I would like to convert this value into 03 for use elsewhere
ie:show single digit numbers as 2 digit in a message box
I've tried variations of the code below but no joy so far

dim txt as string
txt = format(cells(1).value, "00")
msgbox txt
 
J

JLatham

This code seems to work for me with the sheet with A1 holding 3 in it
currently active:

Dim myText As String
myText = Format(ActiveSheet.Cells(1), "00")
MsgBox myText
 
D

David

Thanks J

This is a weird one
Original code worked ok on my home machine
Today works OK on the original machine
When I first posted the problem I was getting a single chr "3" in msgbox
Tried & failed to reproduce the problem today by reformatting cells(1)
Maybe a bug?
Thanks anyway
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top