+ Reply to Thread
Results 1 to 3 of 3

UserForm TexBox formating

Hybrid View

  1. #1
    Registered User
    Join Date
    09-24-2006
    Posts
    11

    UserForm TexBox formating

    I have a user form that uses standard text boxes to display info obtained from a worksheet. All of the info is contained in a single row of that worksheet. The cells that are copied to the form (39 cells which is too much for a standard Excell Dataform) contain various data types such as dates, text and currency amounts. The cells in the worksheet are properly formated to display the data as per the appropriate type. When I copy the cell content to the form, I lose the formating information. Currency amounts such as $3.00 appear as 3. The code I use to display each cell from the sheet to the form is:

    Sub UserForm_Initialize()
     
    Dim ArchiveWks As Worksheet
    Set ArchiveWks = Worksheets("Archive")
    Me.Rate1TBox.Value = ArchiveWks.Cells(r, 18).Value   ' r is the record row
    ' repeated for each text box to Cell pair
    End sub
    My question is:

    How can I format the textbox so that it displays the data in the appropriate format. I can't seem to find the right method to do this.

    Any help would be appriciated

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try adapting his

    With Me
    .Textbox1.Value=Format(Cells(1,1).Value,"Currency")
    .TextBox2.Value=Format(Cells(1,2)>Value,"dd/mm/yy")
    'etc
    Emd With
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    09-24-2006
    Posts
    11
    RoyUk

    Thanks for the tip. It works. I have found what I think is an easier method to copy the cell data to the form. The form is to just display data therefore the actual value is not essential. I found that by using the .Text object it copied the cell contents as is. The code below does what I want:

    Dim ArchiveWks As Worksheet
    Set ArchiveWks = Worksheets("Archive")
    
    With Me       ' Thanks for pointing this out
    
    .Rate1TBox.Value = ArchiveWks.Cells(r, 18).Text   ' r is the record row
    
    ' repeated for each text box to Cell pair
    
    End With
    End sub
    This permits me to eliminate the need to format any of the text boxes

    Thanks for your help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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