VBA - Even though i use a TEXT(<range>,"00") formula my outcome will be "0"

NessPJ

Active Member
Joined
May 10, 2011
Messages
420
Office Version
  1. 365
Hello there,

I am using this code in my VBA routine:
Code:
  Application.Workbooks(RTBook).Sheets(ATTargetSht).Range("BL3:BL" & LastRowPVTable).Formula = "=TEXT(MID(BN3,2,2),""00"")"
    Application.Workbooks(RTBook).Sheets(ATTargetSht).Range("BL3:BL" & LastRowPVTable).Formula = Application.Workbooks(RTBook).Sheets(ATTargetSht).Range("BL3:BL" & LastRowPVTable).Value

Even though i use it, some of my data containing a result value of 02, 03, 04 etc. will end up showing like 2, 3, 4.
I would the result to always exist out of 2 digits. What am i doing wrong here? :)
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
When you do the .Formula = .Value (btw it should be .Value = .Value) you are converting it from Text to a Real number and so it will pick up whatever the format of the cell is.

Custom format the cell as 00 maybe if it is only a visual you require (although if you are doing that there is no point having the text part of the first formula).
 
Last edited:
Upvote 0
I suppose if you do need the data to actual be 2 digits rather than just appear as 2 digits you could try....

Code:
    With Application.Workbooks(RTBook).Sheets(ATTargetSht).Range("BL3:BL" & LastRowPVTable)
        .Formula = "=TEXT(MID(B1,2,2),""00"")"
        .NumberFormat = "@"
        .Value = .Value
    End With
 
Upvote 0

Forum statistics

Threads
1,215,359
Messages
6,124,488
Members
449,165
Latest member
ChipDude83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top