Results 1 to 7 of 7

Thread: CORRECT WAY TO FILL A TEXTBOX

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Thx for the feedback
    Quote Originally Posted by Amelynn View Post
    … take your advice using .Text after TextBox., and .Value2 after .Range. It seems to be the most powerful way if it also takes currency and date formats…...
    Note: .Value2 does not preserve any format: Just to clarify:

    .Value2 is the lowest level number, the most fundamental, the simplist, which Excel holds for the cells value. It is probably most efficient and best to use this if you can, that is to say, Use it if it gets the results that you want.

    .Value is very similar to .Value2. The small difference is that it may give you date and currency values in some format. The final format you get will vary depending on your various settings in your particular Excel.
    ( .Value will often be used by default by Excel in some situations where you referrence the cell by the range object in coding where a value is expected, but you don't specify explicitly what value you want it to use. )

    .Text is new to me. I have not used it much. But my first impression is that it would appear that it gives you the string format similar to what you actually see in the spreadsheet.


    As Example:
    In the attached file, I have a date in the first cell.
    In that attached file is also the macro shown below. If you run that macro, it should give you three different values. Those three different values are the three value properties of the range object of the first cell, .Text , .Value , .Value2
    You will not get exactly the same results as me for .Value and .Text , because the value is influenced by your internal settings and your Land version.
    The value for .Value2 should be exactly the same as what I get, because: For dates in Excel, Excel holds as the most low level value, a number which starts at 1 for the date of January 1, 1900. For the date which I have in the first cell ( 9th September, 2022) Excel has the internal value of 44813.


    Alan








    Code:
    Sub DateValueValue2Text()
    Rem 0 Worksheets info
    Dim Ws1 As Worksheet
     Set Ws1 = ThisWorkbook.Worksheets.Item(1)
    Rem 1 What does the range object hold for the value in first cell
    Debug.Print: Debug.Print "1st cell  .Value  is   " & Ws1.Cells.Item(1).Value & vbCr & vbLf & "1st cell  .Value2  is   " & Ws1.Cells.Item(1).Value2 & vbCr & vbLf & "1st cell  .Text  is   " & Ws1.Cells.Item(1).Text
     MsgBox prompt:="1st cell  .Value  is   " & Ws1.Cells.Item(1).Value & vbCr & vbLf & _
             "1st cell  .Value2  is   " & Ws1.Cells.Item(1).Value2 & vbCr & vbLf & _
               "1st cell  .Text  is   " & Ws1.Cells.Item(1).Text
    End Sub

    Date Value2 Value and Text.jpg
    https://i.postimg.cc/KjFm1988/Date-V...e-and-Text.jpg
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by DocAElstein; 09-13-2022 at 10:43 AM.

Similar Threads

  1. create form with ActiveX combobox, textbox
    By niksirat in forum Excel Help
    Replies: 3
    Last Post: 09-08-2022, 03:24 PM
  2. Align TextBox Within A Range
    By Anshu in forum Excel Help
    Replies: 14
    Last Post: 10-12-2020, 04:12 PM
  3. Formula Editor/Bar in UserForm TextBox?
    By xtinct2 in forum Excel Help
    Replies: 3
    Last Post: 05-23-2017, 12:35 AM
  4. chart placed in correct sheet
    By terrybloome in forum Excel Help
    Replies: 2
    Last Post: 12-06-2013, 05:59 PM
  5. data entry to correct cell range...code needs help
    By paul_pearson in forum Excel Help
    Replies: 2
    Last Post: 08-28-2013, 05:26 PM

Tags for this Thread

Posting Permissions

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