vba format question

  • Thread starter Thread starter David
  • Start date Start date
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
 
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
 
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
 
Back
Top