Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default vba format question

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default vba format question

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


"David" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default vba format question

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

"JLatham" wrote:

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


"David" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
.csv Re-Format Question Bob[_19_] Excel Discussion (Misc queries) 1 April 12th 10 03:01 PM
Format Question SITCFanTN Excel Discussion (Misc queries) 5 April 8th 10 10:28 PM
Yet Another Name Format Question Dallas PM Excel Discussion (Misc queries) 3 April 1st 08 10:01 PM
Format Question Ankeny JJ Excel Discussion (Misc queries) 2 November 21st 06 03:03 PM
Format % Question Stan Atshuller Excel Worksheet Functions 3 October 2nd 06 08:54 PM


All times are GMT +1. The time now is 03:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"