Writing a Currency value to a Worksheet - Not working on Worksheet

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
319
Office Version
  1. 365
Platform
  1. Windows
Hi all - please could someone let me know where I'm going wrong as its driving me mad trying to figure it out.

So I have a userform and the user enters the Total Sale Amount and once exiting the textbox the figure is formatted as a currency which is what I need it to do and it works fine.

VBA Code:
textboxTotalSaleAmount.Value = Format(textboxTotalSaleAmount.Value, "£0.00")

When the user has completed the rest of the boxes on the form and clicks the save button the data is written to the worksheet - again this works fine BUT the worksheet is not recognising the Total Sale amount as a currency (although it does show the '£' symbol). Subsequently the overall Total Sales amounts are not summing on the worksheet.

Does anyone have any idea what I'm missing or doing wrong here?

Many thanks

Paul
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
It is not summing because £5.80 is a string not a number.
Into worksheet cells You have to write 5.80 (and set displaying as currency) then summary will work correct.
Maybe something like this
Excel Formula:
Dim ValueToSaveIntoSheet as long
ValueToSaveIntoSheet = textboxTotalSaleAmount.Value
textboxTotalSaleAmount.Value = Format(textboxTotalSaleAmount.Value, "£0.00")
 
Upvote 1
Hi,
what comes out of a textbox is a string.
When posting to your range you need to coerce to the required datatype using appropriate type conversion function & then apply range.numberformat to display the required format

example.
VBA Code:
      With Range("B10")
            .Value = CCur(Me.textboxTotalSaleAmount.Value)
            .NumberFormat = "£0.00"
         End With

Dave
 
Upvote 0
Thanks so much for the quick reply - sadly that doesn't sort the issue as I've just tested it by entering 11 on the textbox and writing the record to the WS and it still doesn't recognised the value as a currency. I checked the column on the actual WS and it is formatted correctly.
 
Upvote 0
Hi,
what comes out of a textbox is a string.
When posting to your range you need to coerce to the required datatype using appropriate type conversion function & then apply range.numberformat to display the required format

example.
VBA Code:
      With Range("B10")
            .Value = CCur(Me.textboxTotalSaleAmount.Value)
            .NumberFormat = "£0.00"
         End With

Dave

Thanks Dave I'll give that a try - I'm assuming I'd put it in the code for the save button as its referencing the range?
 
Upvote 0
Thanks Dave I'll give that a try - I'm assuming I'd put it in the code for the save button as its referencing the range?

Use in code you post textbox value to the range.
Do be aware using the function your textbox must not be empty otherwise you will get an error.

Dave
 
Upvote 0
Thanks Dave - noted on the textbox not being empty but I've coded that to make sure a user has to put a value in it.
 
Upvote 0
Just to confirm that works now - I had to re jig the code a bit due to the way I'm writing the data to the WS but finally I can move forward.

Thanks again for the responses.
 
Upvote 0
Just to confirm that works now - I had to re jig the code a bit due to the way I'm writing the data to the WS but finally I can move forward.

Just to add, you would do exactly the same for data types like Dates

Glad resolved & appreciate your feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,601
Members
449,109
Latest member
Sebas8956

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