I'm not even sure if I'm on the right track, but I am trying to count the excel rows for a worksheet and display them in a textox on my form. I've assuming it would be best to write the row count in the form load procedure and this is what I've got so far, but no luck getting it to work. If it helps, the "Property" tables is one of the four worksheets created on-the-fly, when the program is started.

Private Sub Item_Number_Tracking(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.load

Dim No_of_Items as Integer
Dim No_of_Items_Text as Integer

No_of_Items = PFC Xpress.Tables("Property").Rows.Count

If No_of_Items = 0 Then
   No_of_Items_Text = 1 & Me.NoOfItems.Text = 1

Else
   Me.NoOfItems.Text =+1

End If

End Sub

Dani AI

Generated

A few practical fixes and a compact, reliable pattern to show the worksheet row count (or the "next item" number) in your textbox.

As ’s snippet shows, the main problems are (a) syntax/name errors (e.g., a space inside the object name), (b) assigning an Integer to a Text property without converting to string, and (c) the incorrect increment =+1. is right that loading the sheet into a DataTable is a clean approach; if you already have a DataSet/DataTable available, read its Rows.Count and set the TextBox.

Safe, minimal example (call this after the "Property" table exists):

Private Sub UpdateItemCount()
    Dim count As Integer = 0

    If PFCXpress IsNot Nothing AndAlso PFCXpress.Tables.Contains("Property") Then
        count = PFCXpress.Tables("Property").Rows.Count
    End If

    ' show actual row count
    NoOfItems.Text = count.ToString()

    ' or, to display the next item number:
    ' NoOfItems.Text = (count + 1).ToString()
End Sub

Notes and troubleshooting

  • Ensure the variable name matches your code (no stray space like PFC Xpress).
  • If the table is created on-the-fly, call UpdateItemCount after creation (or from Form.Shown) — Form_Load may run before the table exists.
  • If you use a DataGridView bound to the table, remember AllowUserToAddRows=True adds a placeholder row; subtract one if needed.
  • To ignore deleted rows use a filter (e.g., count rows where RowState <> DataRowState.Deleted).
  • If you must read directly from an Excel file, use OleDb/ACE or a library like ClosedXML/EPPlus; with Interop, find the last used row with Worksheet.Cells(...).End(xlUp).Row and always release COM objects.

Follow this pattern and the textbox will reliably display the correct count or next item number.

You could do some work around if your using database

Try to upload your excel to a datatable then count the number of rows

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.