Results 1 to 6 of 6

Count number of TextBoxes with certain name(s)

Threaded View

Maki Count number of TextBoxes... 12-21-2014, 12:43 AM
LJMetzger Re: Count number of TextBoxes... 12-21-2014, 06:15 PM
Maki Re: Count number of TextBoxes... 12-22-2014, 08:27 AM
Norie Re: Count number of TextBoxes... 12-22-2014, 08:37 AM
LJMetzger Re: Count number of TextBoxes... 12-22-2014, 11:34 AM
Maki Re: Count number of TextBoxes... 12-22-2014, 05:30 PM
  1. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Count number of TextBoxes with certain name(s)

    Hi Maki and Norie,

    Thanks Norie for updating Maki's code. In Norie's code I got a run time error when one of the Score Text Boxes was BLANK or contained a non-numeric character. See the attached (hopefully) corrected workbook and code that follows.

    The dangling If without an Endif caused the for loop compile error.

    Norie's changes in GREEN. My changes in Red:
    Sub CalculateScores()
    Dim ctrl As MSForms.Control
    Dim judgecategory As Variant
    Dim i As Long, j As Long, k As Long
    Dim iscore As Double, maxscore As Double, subtotal As Double
    Dim ctrlname As String, scoreboxname As String, maxscorelabelname As String
    
        judgecategory = Array("RoutineContent", "TechnicalMerit", "MusicalInterpretation")
        For i = LBound(judgecategory) To UBound(judgecategory)
            j = 0
            For Each ctrl In Me.Controls
                ctrlname = ctrl.Name
                If Left(ctrlname, Len(ctrlname) - 1) = "txt" & judgecategory(i) & "Score" Then
                    j = j + 1
                End If
            Next ctrl
    
            subtotal = 0
            For k = 1 To j
                scoreboxname = CStr("txt" & judgecategory(i) & "Score" & k)
                maxscorelabelname = CStr("lbl" & judgecategory(i) & "MaxP" & k)
                iscore = 0
                On Error Resume Next
                iscore = CDbl(Me.Controls(scoreboxname).Value)
                On Error GoTo 0
                maxscore = CDbl(Me.Controls(maxscorelabelname).Caption)
                If iscore > maxscore Then
                    Me.Controls(scoreboxname).BackColor = vbRed
                End If
                subtotal = subtotal + iscore
            Next k
            Me.Controls("txt" & judgecategory(i) & "Subtotal").Value = subtotal
        Next i
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Unique Ref number based on textboxes
    By johnny_p in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2014, 04:35 AM
  2. Replies: 1
    Last Post: 09-15-2014, 03:08 PM
  3. VBA Excel - COUNT, AVG, & MIN with textboxes
    By patrickmt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-14-2013, 02:12 PM
  4. userform to count cell colours and display in textboxes
    By AGrace in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2011, 09:39 AM
  5. [SOLVED] Count number of textboxes
    By april27 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-19-2006, 06:40 AM

Tags for this Thread

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