+ Reply to Thread
Results 1 to 21 of 21

Userform Formatting Not Correct for Currency and Percentage Values

  1. #1
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Userform Formatting Not Correct for Currency and Percentage Values

    Hi, I really hope someone can assist!

    I have attached a workbook with a working userform for easy reference.

    I have a userform that when you click the All Students or Current Students buttons, this would populate a main listbox called "ResultBox" and I would like to achieve the following:

    1. Fix the formatting in the ResultBox so that the last 3 columns show the correct formatting. Currency amounts (3rd and last columns)with 2 decimal places, and a percentage(%) amount with 2 decimal places in the second last column

    2. Name the columns in the Resultbox according to the columns referenced to in the database sheet (DB)

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    This will give you an idea...

    Why pass a column to the array if the column width is zero...Why not just leave the column out...
    And stop adding multiple blank rows to your Tables...As suggested in other post...
    When you pass info to the table, it automatically takes on the formats...So no need for all the blank rows...DELETE THEM...

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 07-24-2020 at 02:51 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Hi sintek, a fellow SA I see thanks for the quick reply!

    Thing is I know very little of VBA and have to rely on the expertise of fellow forum members and trust that code I receive works best.

    Any help with optimised code will be appreciated though, but so far just using the code provided here that just works (bloated or not), not the best way but atleast works for now.

    But still really appreciate the help I get from forum members

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Hi sintek, a fellow SA I see thanks for the quick reply!
    Yes...hallo daar mater...

    So does the above code solve part 1?
    What i meant about the column widths set to 0...Just remove those column numbers from the array if you are not needing them... i.e. 4 & 6

  5. #5
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Quote Originally Posted by sintek View Post
    Yes...hallo daar mater...

    So does the above code solve part 1?
    What i meant about the column widths set to 0...Just remove those column numbers from the array if you are not needing them... i.e. 4 & 6
    Dankie maat,

    It works fine in the example book but not in my project book - I suspect it is due to all the extra empty rows I have but I can't just delete them (see explanation below)
    As for the column widths (zeros). No I can't just remove those columns because on the userform listbox (ResultBox), only specific columns data must be displayed in a certain order (like 20 comes before 18, 19). Therefore out of the 20 columns in the DB sheet only 7 specific columns are displayed in ResultBox but then when you click on a "student" in ResultBox then ListBox2 would then display additional data not displayed in ResultBox. My current code all works 100% but just need to get the formatting right preferably by using the same code I provided if possible. So your "new" structured code is no working in my project book.

    Explanation...The problem is that the example workbook I shared here is only a fraction of the size of my actual project workbook so I have to replicate as best as I can the example book to get my point across.

    In my project workbook I have to use data stored on DB sheet that has about 90 rows (continuously increasing) that stores input data over 773 columns from about 60 different worksheets, where the example book only uses 10 rows in the DB sheet and 2 worksheets, just to try replicate my project workbook (which is a monster workbook ) so I can't just delete all these empty rows and columns in this example book.

    I can however delete all the empty rows but if a new "student" has to be saved to the DB sheet using another set of code (not included in this example book) that would need to increase the table size by adding in another line below the entry every time a new "student" is added, but currently don't have that function therefore there are many extra rows currently in the table that need be in the DB sheet.

    Sorry for the long message but things are just not that simple

    So just to clarify I need to fix the formatting of the last three columns of listbox "Resultbox" preferably using my existing code (that works 100% for what it must do) just to make things simpler to implement on my project workbook?

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    I can however delete all the empty rows but if a new "student" has to be saved to the DB sheet using another set of code (not included in this example book) that would need to increase the table size by adding in another line below the entry every time a new "student" is added, but currently don't have that function therefore there are many extra rows currently in the table that need be in the DB sheet.
    Yes, just incorporate the proper little code snippet that enters that 1 new student into the next available row of the table...This would be the correct coding practice and not having to manually insert hundreds of rows all the time...

    So just to clarify I need to fix the formatting of the last three columns of listbox "Resultbox" preferably using my existing code (that works 100% for what it must do)
    Okay, here it is...Just remember currently your listbox is not wide enough to accommodate the column widths...You will need to set the scroll bar property to true or increase your listbox width...
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Quote Originally Posted by sintek View Post
    Yes, just incorporate the proper little code snippet that enters that 1 new student into the next available row of the table...This would be the correct coding practice and not having to manually insert hundreds of rows all the time...



    Okay, here it is...Just remember currently your listbox is not wide enough to accommodate the column widths...You will need to set the scroll bar property to true or increase your listbox width...
    Please Login or Register  to view this content.
    Fantastic thank you (dankie ) it works great! I just have 2 questions:

    1. Is it possible to make the column headers static so they don't move if you have to scroll down the listbox because there are many "students"?
    2. Is it possible to adjust the alignment of each individual column e.g. column 1= centre alignment, column 2 = alignment left, column 3 = alignment right for example etc?

  8. #8
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Okay, here it is...Just remember currently your listbox is not wide enough to accommodate the column widths...You will need to set the scroll bar property to true or increase your listbox width...
    Please Login or Register  to view this content.
    [/QUOTE]

    Your code works great with
    Please Login or Register  to view this content.
    but can you please do the same for
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    as these formats also need to be fixed

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Hi Rudi...No need to quote entire posts...just clutters thread..

    Please Login or Register  to view this content.
    As per your populating Table...A example only

    This would be a stable code to fill your Table properly even if Empty...You wont need to have hundreds of extra lines...This code populates next available row...
    Just in case you want to fix your Main Files code and remove those unnecessary lines...

    Please Login or Register  to view this content.
    Not sure what your search code is doing...what is SEARCH criteria normally...What would be typed in?
    Last edited by sintek; 07-25-2020 at 03:39 AM.

  10. #10
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Quote Originally Posted by sintek View Post

    Not sure what your search code is doing...what is SEARCH criteria normally...What would be typed in?
    Thanks for the Private Sub cmdCurrent_Click() code...it works great.

    The search has no specific criteria it is just for general searching of the Array(1, 2, 4, 5, 6, 9, 15, 20, 18, 19) columns, because as I mentioned before the amount of rows are always increasing so a search function would become necessary to do a quick search when there are lots of "students" so was hoping to get the correct formatting code for this also.

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    So what would User type in...

  12. #12
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Quote Originally Posted by sintek View Post
    So what would User type in...
    Mostly by Name, Last Name, ID number, but could also search for student number, class. These would be the main ones to search for. But anything really in columns 1, 2, 4, 5, 6, 9, 15, 20, 18, 19 in the DB

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Mostly by Name, Last Name, ID number, but could also search for student number, class
    Not happy with your current code...
    Is the search criteria entered completely...Why are you making use of wildcard search...

  14. #14
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Quote Originally Posted by sintek View Post
    Not happy with your current code...
    Is the search criteria entered completely...Why are you making use of wildcard search...
    As with all my code I am using currently it was provided to me on this forum by other members, so I use the code it if it works and does the job which my current code seems to do.

    Currently you don't have to enter in lets say the whole "last name" for instance, then it will display all names with the same info to narrow down your search to select the one you want. So current code working pretty good so far, just the formatting as with previous posts needs to be the same as others.

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Okay...For your current code provided by OP...
    Insert red snippet
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Quote Originally Posted by sintek View Post
    Okay...For your current code provided by OP...
    Insert red snippet
    Awesome thanks!!

    Do you perhaps a a solution to my previous other 2 questions...

    Fantastic thank you (dankie ) it works great! I just have 2 questions:

    1. Is it possible to make the column headers static so they don't move if you have to scroll down the listbox because there are many "students"?
    2. Is it possible to adjust the alignment of each individual column e.g. column 1 = centre alignment, column 2 = alignment left, column 3 = alignment right for example etc?

  17. #17
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    AFAIK One can only freeze top row if ColumnHeads is set to True and Listbox is populated by RowSource Which includes data only...
    Alternatively, you can manually insert labels above the listbox...
    As for alignment...See here

  18. #18
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Quote Originally Posted by sintek View Post
    AFAIK One can only freeze top row if ColumnHeads is set to True and Listbox is populated by RowSource Which includes data only...
    Alternatively, you can manually insert labels above the listbox...
    As for alignment...See here
    Thanks I will have a look into that!

    I think that is it for this post so I will mark it as solved.

    I am going to make another new post just now if you could help there also, would be much appreciated, but thanks for all your help and effort here!

  19. #19
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,215

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Cool...Thanks for adding to my reputation +

  20. #20
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    I blinked and the problem was solved by the time I found the link again.
    Rather than condemn my effort to the bin it is attached in case the odd snippet proves useful.
    torachan.
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    07-13-2014
    Location
    Three Rivers
    MS-Off Ver
    365
    Posts
    127

    Re: Userform Formatting Not Correct for Currency and Percentage Values

    Quote Originally Posted by torachan View Post
    I blinked and the problem was solved by the time I found the link again.
    Rather than condemn my effort to the bin it is attached in case the odd snippet proves useful.
    torachan.
    Thanks for this! and for the effort...really appreciate it!

+ 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. [SOLVED] User form not formatting textbox date/currency values
    By rob_h in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-23-2017, 07:52 AM
  2. Formatting values in listbox to show currency
    By chrisellis250 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2017, 11:39 AM
  3. [SOLVED] Percentage values in combobox userform
    By Crispy85 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-09-2017, 08:21 AM
  4. Need userform to add new row with correct formatting, then add info from textbox
    By cactusmop in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-10-2016, 08:57 PM
  5. [SOLVED] Conditional Formatting Partial Currency Values in One Column
    By bmann021 in forum Excel General
    Replies: 9
    Last Post: 08-27-2015, 11:40 AM
  6. Need Excel to automatically select correct columns to sum their values by currency
    By gerhardmiener in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-14-2013, 03:16 PM
  7. Replies: 8
    Last Post: 02-15-2011, 11:40 AM

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