Full Code
Imports ClosedXML.ExcelPublic Class Form1Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickTryUsing workb As New XLWorkbook("H:\Names2.xlsx")Dim worksh = workb.Worksheet("Sheet4")Dim lastrow As Integer = worksh.LastRowUsed.RowNumber()Dim idfound As Boolean = FalseFor i As Integer = 2 To lastrowIf worksh.Cell(i, 1).GetValue(Of Integer) = CInt(TextBox1.Text) ThenTextBox2.Text = worksh.Cell(i, 2).GetString()TextBox3.Text = worksh.Cell(i, 3).GetString()TextBox4.Text = worksh.Cell(i, 4).GetString()idfound = TrueExit ForEnd IfNextIf Not idfound ThenTextBox2.Text = ""TextBox3.Text = ""TextBox4.Text = ""End IfEnd UsingCatch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd SubEnd Class
No comments:
Post a Comment