snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Code นั้นเป็นการใช้ฟังก์ชั่น Match ซึ่งหากไม่พบข้อมูลก็จะเกิด Error ปกติก่อนที่จะ Match เราควรจะนับเสียก่อนว่ามีหรือไม่มีเช่นใช้ Countif หากมีแล้วค่อย Match อีกที ถ้าไม่มีก็ให้ออกจากคำสั่งไป เช่นนี้เป็นต้นครับ
Private Sub CommandButton6_Click()
'On Error Resume Next
Dim id As String
Dim rowselect As String
If TextBox7.Text = "" Then
MsgBox ("Please select data")
Else
id = TextBox7.Text
rowselect = WorksheetFunction.CountIf(Worksheets("¡ÒÃàºÔ¡").Range("A2:A10000"), 0)
rowselect = WorksheetFunction.Match(id, Sheet9.Range("A2:A10000"), 0)
Rows(rowselect).Select
Rows(rowselect).EntireRow.Delete
If MsgBox("Are you sure want to delete to data?", vbYesNo) = vbYes Then
Unload Me
End If
End If
Unload Me
Requisition.Show
End Sub
Private Sub CommandButton6_Click()
'On Error Resume Next
If TextBox7.Text = "" Then
MsgBox ("Please select data")
Exit Sub
Else
Dim id As String
Dim rowselect As String
id = TextBox7.Text
rowselect = WorksheetFunction.CountIf(Worksheets("การเบิก").Range("A1:A10000"), id)
If rowselect = 0 Then
Exit Sub
Else
rowselect = WorksheetFunction.Match(id, Sheet9.Range("A1:A10000"), id)
Rows(rowselect).Select
Rows(rowselect).EntireRow.Delete
End If
If MsgBox("Are you sure want to delete to data?", vbYesNo) = vbYes Then
Else
UserForm1.Show
Unload Me
End If
End If
Unload Me
UserForm1.Show
End Sub
Private Sub CommandButton6_Click()
'On Error Resume Next
If TextBox7.Text = "" Then
MsgBox ("Please select data")
Exit Sub
Else
Dim id As String
Dim rowselect As String
If id = TextBox7.Text Then
Exit Sub
Else
rowselect = WorksheetFunction.CountIf(Worksheets("การเบิก").Range("A1:A10000"), id)
End If
If rowselect = 0 Then
Exit Sub
Else
rowselect = WorksheetFunction.Match(id, Sheet9.Range("A1:A10000"), 0)
Rows(rowselect).Select
Rows(rowselect).EntireRow.Delete
End If
If MsgBox("Are you sure want to delete to data?", vbYesNo) = vbYes Then
Unload Me
End If
End If
Unload Me
Requisition.Show
End Sub
'Other code
Dim id As String
Dim rowselect As Long
If TextBox7.Text = "" Then
MsgBox ("Please select data")
Exit Sub
Else
id = Me.TextBox7.Text
If WorksheetFunction.CountI(Sheet9.Range("A1:A10000"), id) > 0 Then
rowselect = WorksheetFunction.Match(CLng(id), Sheet9.Range("A1:A10000"), 0)
Else
Exit Sub
End If
Rows(rowselect).EntireRow.Delete
'Other code
End If
'Other code
Private Sub CommandButton6_Click()
'On Error Resume Next
Dim id As String
Dim rowselect As Long
If TextBox7.Text = "" Then
MsgBox ("Please select data")
Exit Sub
Else
id = Me.TextBox7.Text
If WorksheetFunction.CountIf(Sheet9.Range("A1:A10000"), id) > 0 Then
rowselect = WorksheetFunction.Match(CLng(id), Sheet9.Range("A1:A10000"), 0)
Else
Exit Sub
End If
Rows(rowselect).EntireRow.Delete
rowselect = WorksheetFunction.CountIf(Worksheets("¡ÒÃàºÔ¡").Range("A1:A10000"), id)
If rowselect = 0 Then
Exit Sub
Else
rowselect = WorksheetFunction.Match(id, Sheet9.Range("A1:A10000"), 0)
Rows(rowselect).Select
Rows(rowselect).EntireRow.Delete
End If
If MsgBox("Are you sure want to delete to data?", vbYesNo) = vbYes Then
Unload Me
UserForm1.Show
End If
End If
End Sub
You do not have the required permissions to view the files attached to this post.
Private Sub btsearch_Click()
'On Error Resume Next
If ComboBox1 = "" Or ComboBox2 = "" Then
MsgBox "Please fill the complete data"
Exit Sub
End If
Dim found As Boolean
Dim txt As String
Dim r As Range
Dim nRow As String
Sheet4.Activate
For Each r In Sheet4.Columns(1).SpecialCells(xlCellTypeConstants)
'If Right(r.Value, 3) = Right(ComboBox1.Text, 3) And
If ComboBox2.Text = Application.Text(r.Offset(0, 1).Value, ComboBox2.Text) Then
nRow = r.Row
found = True
Exit For
End If
Next r
If found Then
txt = Cells(nRow, 6)
TextBox1.Text = txt
Exit Sub
Else
MsgBox "Data not found !"
End If
'Sheet1.Activate
End Sub
You do not have the required permissions to view the files attached to this post.
'Other code
For Each r In Sheet4.Columns(2).SpecialCells(xlCellTypeConstants)
'If Right(r.Value, 3) = Right(ComboBox1.Text, 3) And
' If ComboBox2.Text = Application.Text(r.Offset(0, 1).Value, ComboBox2.Text) Then
If (r.Value = ComboBox2.Text And r.Offset(0, -1).Value = ComboBox1.Text) Or _
r.Value = ComboBox2.Text And r.Offset(0, -1).End(xlUp).Value = ComboBox1.Text Then
' r.Value = comb
nRow = r.Row
found = True
Exit For
End If
Next r
'Other code