+ Reply to Thread
Results 1 to 10 of 10

Userform textbox code

Hybrid View

CJ-22 Userform textbox code 10-29-2008, 12:13 PM
royUK This will show how many cells... 10-29-2008, 12:21 PM
CJ-22 Thanks for the reply. That... 10-29-2008, 01:12 PM
royUK How can you change the cells... 10-29-2008, 01:15 PM
CJ-22 The userform itself changes... 10-29-2008, 01:58 PM
royUK Just add this to the end of... 10-29-2008, 02:00 PM
CJ-22 That works great, but I have... 10-29-2008, 03:20 PM
royUK Glad we helped, pleaqse mark... 10-30-2008, 10:27 AM
  1. #1
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125

    Userform textbox code

    I have a userform and I want a textbox that counts cells J7,M7,P7,S7,V7. Does anyone know how to write this code and where to put it. All I want is the textbox to show how many cells of these five have data in them and I want it to update automatically.

    Thanks for any help.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    This will show how many cells contain data in the range, don't know what you mean by update automatically

    Private Sub UserForm_Initialize()
    Me.TextBox1.Value = Application.WorksheetFunction.CountA(Range("J7, M7, P7, S7, V7"))
    End Sub
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125
    Thanks for the reply. That works, but with one problem. I need this to update in real time. This only updates when the userform is opened. Is there a way to update this anytime the data changes?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    How can you change the cells with the userform open, unless it is modeless.

  5. #5
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125
    The userform itself changes the cells. Each time I press a button on the userform, the cells update. I need the textbox to update each time the cells update.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Just add this to the end of your button's code

    UserForm_Initialize

  7. #7
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125
    That works great, but I have one more question. Is there any way to show blank instead of 0 when the cells are empty?

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The code only needs slight modification

      Dim lChk   As Long
        lChk = Application.WorksheetFunction.CountA(Range("J7, M7, P7, S7, V7"))
        If lChk > 0 Then
            Me.TextBox1.Value = lChk
        Else: Me.TextBox1.Value = vbNullString
        End If

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Glad we helped, pleaqse mark the thread solved

+ 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