Try to count row with data and specific value from excel in VB.net

  • Thread starter Thread starter SoNewBie
  • Start date Start date
S

SoNewBie

Guest
So I have 2 Labels (lblTotal) and (lblYes) which I put on form. I want to read excel file and count how many people coming and how many say "yes" like this (picture). so "lblTotal" will count all row with data exclude header and "lblYes" will show the counting of Answer with "Yes" which update in realtime.

so far I can only open excel file.

Dim xlApp As Excel.Application = Nothing
Dim xlWorkBooks As Excel.Workbooks = Nothing
Dim xlWorkBook As Excel.Workbook = Nothing
Dim xlWorkSheet As Excel.Worksheet = Nothing
Dim xlWorkSheets As Excel.Sheets = Nothing
Dim xlCells As Excel.Range = Nothing
Public Sub Total()
xlApp = New Excel.Application
xlApp.DisplayAlerts = False
xlWorkBooks = xlApp.Workbooks
xlWorkBook = xlWorkBooks.Open("D:\Question\Data.xlsx")
xlApp.Visible = False
xlWorkSheets = xlWorkBook.Sheets
End Sub

I think I might need this code to count the row with data. Credit to nixda's answer in stackoverflow.

Lastrow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row

But I am not sure about count with specific value and how to get to it. So far I am stuck after open excel file dont know where to go.

sample to my excel: View: https://imgur.com/a/llfgt6h


Edit: I tried add this but seem it count all of the row instead.

Dim xx As Integer = xlApp.Application.Rows.Count
lblTotal.Text = xx.ToString()

Continue reading...
 
Back
Top