+ Reply to Thread
Results 1 to 4 of 4

Fill textbox with the value of a cell

Hybrid View

  1. #1
    Registered User
    Join Date
    07-25-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    2010
    Posts
    17

    Fill textbox with the value of a cell

    Hello.
    I have a code that have to fill a textbox with the value of last non empty cell from column F in active sheet.
    This code doesn't work, the textbox in frmInregistrare remain empty.
    The cause is because cells from column F isn't really empty, all cells have formulas.
    I think I know which is the wrong line but I don't know how it have to be modified.
    Could you help me, please?
    I've attached an example.
    Thanks.

    The code that I have is follow:
    Private Sub UserForm_Initialize()
       
        Dim ws As Worksheet
        Dim lstRw As Long
       
            Set ws = ActiveSheet
           
            With ws
            lstRw = .Rows.Count
            Me.txtDocNumber = .Range("F" & lstRw).End(xlUp).Value     ' This I think is the wrong line
            End With
           
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Fill textbox with the value of a cell

    The .Find method can return the last used cell value excluding null strings (i.e. "")

    Private Sub UserForm_Initialize()
        
        Me.txtDocNumber = Range("F:F").Find("*", , xlValues, , , xlPrevious).Value
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,445

    Re: Fill textbox with the value of a cell

    Perhaps something like this??
    Private Sub UserForm_Initialize()
        
        Dim ws As Worksheet
        Dim lstRw As Long
        
            Set ws = ActiveSheet
            
            With ws
            lstRw = .Cells(.Rows.Count, "F").End(xlUp).Row
            Me.txtDocNumber = .Cells(lstRw, "F").Value
            End With
            
    End Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    07-25-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    2010
    Posts
    17

    Re: Fill textbox with the value of a cell

    Both of codes work perfectly.
    Thank you @AlphaFrog and @MarvinP.

    The following code also works fine.

    Private Sub UserForm_Initialize()
        Dim ws As Worksheet
        Dim i As Long
        Set ws = ActiveSheet: i = 6
        Do
        i = i + 1: Loop While ws.Range("F" & i + 1) <> ""
        Me.txtDocNumber = ws.Range("F" & i)
        Set ws = Nothing
    End Sub

+ 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] Create a text box for each row of data and fill that textbox with concatenated cell value.
    By Goldbadger in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2015, 07:19 AM
  2. Fill a cell via textbox according to combobox selection
    By dj_danu01 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-15-2013, 08:12 AM
  3. [SOLVED] Fill a cell via textbox on userform depending on combobox selection
    By Rhamilton2512 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2012, 10:29 AM
  4. Textbox fill and edit a cell
    By monttaup in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-02-2012, 11:20 AM
  5. [SOLVED] VBA UserForm - Have entry in TextBox fill Another TextBox by VLOOKUP
    By msquared99 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-26-2012, 10:24 PM
  6. Userform textbox to fill next blank cell in column
    By RaffertyL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2012, 03:20 AM
  7. Fill Textbox from cell
    By V. Roe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2005, 04:05 PM

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