Count number of textbox with specific name

dandelion

New Member
Joined
Jul 16, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi, is there any way to count number of textbox with specific name in Excel? For example, I have a large of design containing many trays (pics are illustration only). I would like to count number of Racks in this sheet? The textboxes names are Textbox 1, textbox 2....

Screenshot 2022-09-20 at 10.58.04 AM.png
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Assuming that the relevant textboxes are named TextBox 1 through TextBox 7, you can use the following custom function to get your count. First add the following code to your workbook in a regular module (Visual Basic Editor >> Insert >> Module)...

VBA Code:
Function GetRackCount(ByVal sheetname As String, ByVal criteria As String) As Long

    Application.Volatile

    Dim rackCount As Long
    Dim i As Long
 
    rackCount = 0
    For i = 1 To 7
        If UCase(Worksheets(sheetname).TextBoxes("TextBox " & i).Text) = UCase(criteria) Then
            rackCount = rackCount + 1
        End If
    Next i
 
    GetRackCount = rackCount
 
End Function

Then you can use any of the following worksheet formulas...

Excel Formula:
=GetRackCount("Sheet1", "Rack")

=GetRackCount("Sheet1", A2)  'where A2 contains Rack

=GetRackCount(A2, B2) 'where A2 contains Sheet1 and B2 contains Rack

Change the sheet name and cell references accordingly. Note that in order to update the formula you'll need to press either Shift+F9 to calculate the worksheet or F9 to calculate the workbook. Also, the formula will automatically update when there's a change in any cell within the workbook.

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top