Format Textbox not working

tbeards

New Member
Joined
May 27, 2009
Messages
47
I am having trouble with some code that is puzzling me. Basically, I have a userform that upon opening, I want the textboxes to show values from a spreadsheet in the same format as the spreadsheet. The spreadsheet uses named ranges ("Annual_Gallons", "GallonsLowTier1_txt" and "GallonsLowTier2_txt"). The formatting works for the Annual_Gallons but doesn't for the other two. For example, in my spreadsheet I have 50,000 for GallonsLowTier1_txt and it is appearing without the , (comma). The first one, "Annual Gallons", is showing up just fine with the comma (value is 258,568). I am puzzled. Any ideas? My text box names are the same as the cell named ranges and I have double checked that they are spelled the same...

Thanks beforehand!

Private Sub UserForm_Initialize()

FuelRebateVolumeGallons_txt.Value = Format(Worksheets(constSheetFuel).Range("Annual_Gallons").Value, "#,##0") 'works
GallonsLowTier1_txt.Value = Format(Worksheets(constSheetAdministration).Range("GallonsLowTier1_txt").Value, "#,##0") 'doesn't work
GallonsLowTier2_txt.Value = Format(Worksheets(constSheetAdministration).Range("GallonsLowTier2_txt").Value, "#,##0") 'doesn't work


End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Use Text instead of Value.

That should return the value from the worksheet as it is formatted on the worksheet.:)
 
Upvote 0
Boy oh boy do I feel dumb. I realized I had the Control Source property populated with the values I was bringing into the userform, except the one that worked!. I deleted all of the CS properties and it works.

Thanks for the reply though as that worked as well!

~t
 
Upvote 0
I mean your post worked as well as the .value but it wouldn't have worked the way it was before I deleted the CS properties.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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