สอบถามเพิ่มเติมคับอาจารย์ snasui
1.ถ้าต้องการให้ Reference No. มาโชว์ ต้องปรับ Code อย่างไรครับ
2.ถ้าต้องการคลิกค่าใน ListBox1 แล้วทำการคลิกปุ่ม Delete ข้อมูลที่คลิก Row ใน Sheet "Data" จะหายไป ต้องปรับ Code อย่างไรครับ ขอบคุณครับ
Code: Select all
Sub Button3_Click()
Dim i, lastrow As Long
lastrow = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row
If MsgBox("Are you sure you want to delete the row?", vbYesNo + vbQuestion, "Delete row") = vbYes Then
'Other code
Dim temp As Variant
For i = 1 To lastrow
If Cells(i, 6) = ListBox1.List(ListBox1.ListIndex) Then
If Cells(i + 1, 2).Value <> "" Then
temp = Range(Cells(i + 1, 2), Cells(Rows.Count, 2).End(xlUp)).Resize(, 2)
Range(Cells(i, 6), Cells(Rows.Count, 3).End(xlUp)).ClearContents
Cells(i, 6).Resize(UBound(temp, 1), 2).Value = temp
Else
Range(Cells(i, 6), Cells(Rows.Count, 3).End(xlUp)).ClearContents
End If
Exit For
End If
Next i
'Other code
End If
End Sub