+ Reply to Thread
Results 1 to 13 of 13

Controlsource: keep cell formatting

  1. #1
    Registered User
    Join Date
    01-14-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    7

    Lightbulb Controlsource: keep cell formatting

    Hey All

    I am losing my sanity haha!!!

    It seems so simple but I cannot for the life of me find a solution. I have a textbox on a userform that is linked via controlsource to a cell on sheet1 - call it A1. A1 is simply a sum of values (which constantly changes) and it is formatted as currency. All I would like is to carry over range("A1").text to my textbox so that it keeps the currency formatting.

    Why does this seem so impossible? All I want is something like the controlsource property to be A1.text, not just A1 where I get a value.

    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Controlsource: keep cell formatting

    ControlSource will not take the formatting, it will only take the value.

    You could simply populate the textbox yourself like this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-14-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Controlsource: keep cell formatting

    Thanks Norie. Well at least I'm not mad. I appreciate your response, but I need this textbox to update whenever the source cell changes. A worksheet change just seems a bit unnecessary for something which in my mind is so darn simple..

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Controlsource: keep cell formatting

    What worksheet change event?

    What exactly do you have in A1, how is it updated and when are you displaying the userform?

    PS If you try formatting the value in the textbox you'll lose whatever you have in A1 as it will be overwritten with the textbox value, which is why using ControlSource usually isn't a good idea.

  5. #5
    Registered User
    Join Date
    01-14-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Controlsource: keep cell formatting

    Well I'd like the textbox/label (I chose textbox because I figured controlsource was the most reasonable option) to constantly update with A1. A1 is a sum of hundreds of costs.

    So I'd like a label/textbox to update on the userform as the user selects different options. Which is all good with controlsource but I can't keep the currency formatting...

    Obviously this label/textbox won't be available for edit by the user.

    Thanks Norie!

  6. #6
    Registered User
    Join Date
    01-14-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Controlsource: keep cell formatting

    The userform lets you choose options like type/quantity/etc through optionbuttons and checkboxes, the results are posted to a worksheet where the final price is calculated - but it is a fairly complex procedure and simple options can have huge effects on the final price.

    The label is very useful for keeping track of the changes to price according to the options you choose.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Controlsource: keep cell formatting

    So how/when are you displaying the userform?

    Also, how/where is the user selecting options?

  8. #8
    Registered User
    Join Date
    01-14-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Controlsource: keep cell formatting

    You choose a product which is a commandbutton - this opens a userform where you can further specify product options. The worksheet recalculates whenever an option is chosen/edited, and the final price after markup etc is displayed in A1. A textbox with a controlsource to A1 works perfectly but as you say you lose the formatting..

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Controlsource: keep cell formatting

    Where are these option buttons located?

    By the way, the code I posted was intended for the userform Initialize event which runs whenever the form is shown.

  10. #10
    Registered User
    Join Date
    01-14-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Controlsource: keep cell formatting

    Temp.jpg

    Ok so the price summary is actually in B7, and the textbox displays that figure at the bottom of the userform

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Controlsource: keep cell formatting

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  12. #12
    Registered User
    Join Date
    01-14-2014
    Location
    South Africa
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Controlsource: keep cell formatting

    I'm afraid I can't too much sensitive information!

    Anyway, thanks for your time Norie, I have just linked a label to the range.text on a worksheet change event, and that seems to be working ok Have I misunderstood sourcecontrol? I'm now noticing that the textbox fixes B7 but I'm not sure if I have done something strange to cause that.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    We don't need, or want, to see any sensitive data.

    If you use ControlSource it's a 2-way thing, any value from the linked cell will goto the textbox and any value put in the textbox will go in the linked cell.

    So if you had a formula in A1 and that was linked, via ControlSource, to TextBox1 the value from A1 would go in the textbox1.

    If you then changed/deleted the value in TextBox1 that value would go to A1, overwriting whatever was previously on the cell.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. .ControlSource
    By Ctech in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2006, 08:20 AM
  2. Controlsource Puzzlement
    By Francis Knight in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-14-2005, 05:25 PM
  3. [SOLVED] TextBox ControlSource
    By marwan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2005, 02:05 PM
  4. Controlsource errors
    By Mats Samson in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-04-2005, 12:05 PM
  5. [SOLVED] ControlSource
    By Greg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2005, 12:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1