[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Converting a number to text using FORMAT in VBA, using a cell number format

Hi there,

I am trying to populate a textbox in a user form with a number from a cell in a worksheet.  The format of the source cell will vary and can include some custom number formats.  I want to try and use the actual numberformat property of the cell when formatting the number as text in the textbox.  Is this possible?  I don't think the formats used in the VBA Format function are able to directly use the cell numberformat property (or am I wrong?), but is there something clever I can do that doesn't involve an inordinate amount of coding that will achieve this?

Many thanks,

1 Solution
If I'm understanding you correctly, instead of using the format() method, you could just use the text property of the cell.

Let's say you have cell "A1" with the number 1234, formatted as shown there.
Range("A1").text in VBA will produce the string "1234"

Let's say you change the formatting in cell "A1" so it shows "1,234.00"
Range("A1").text in VBA will produce the string "1,234.00"

is that what you're looking for?
DigitttAuthor Commented:
Spot on and can't believe I hadn't come across the property before.

Many thanks!


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now