Public Sub search()
Dim stepin As Variant
Dim search_a As Byte
Dim check_a As Byte
Dim search_b As String
Dim check_b As String
Dim b As Variant
Dim c As Variant
Dim d As Variant
Dim e As Variant
Dim f As Variant
Dim g As Variant
Dim h As Variant
Dim i As Variant
Dim z As Integer
Dim data_row As Single
Const b_col = 2
Const a_col = 1
Const c_col = 3
Const d_col = 4
Const e_col = 5
Const f_col = 6
Const g_col = 7
Const h_col = 8
Const i_col = 9
z = 4
data_row = 3
b = Worksheets("sheet1").Cells(data_row, b_col).Value
a = Worksheets("sheet1").Cells(data_row, a_col).Value
c = Worksheets("sheet1").Cells(data_row, c_col).Value
d = Worksheets("sheet1").Cells(data_row, d_col).Value
e = Worksheets("sheet1").Cells(data_row, e_col).Value
f = Worksheets("sheet1").Cells(data_row, f_col).Value
g = Worksheets("sheet1").Cells(data_row, g_col).Value
h = Worksheets("sheet1").Cells(data_row, h_col).Value
i = Worksheets("sheet1").Cells(data_row, i_col).Value
search_a = Worksheets("sheet2").Cells(z, 1).Value
z = z + 1
With Worksheets("sheet1")
Do Until check_a = search_a
data_row = data_row + 1
check_a = Worksheets("sheet1").Cells(data_row, a_col).Value
Loop
End With
z = 4
With Worksheets("sheet2")
.Cells(z, 2).Value = Worksheets("sheet1").Cells(data_row, b_col).Value
.Cells(z, 3).Value = Worksheets("sheet1").Cells(data_row, c_col).Value
.Cells(z, 4).Value = Worksheets("sheet1").Cells(data_row, d_col).Value
.Cells(z, 5).Value = Worksheets("sheet1").Cells(data_row, e_col).Value
.Cells(z, 6).Value = Worksheets("sheet1").Cells(data_row, f_col).Value
.Cells(z, 7).Value = Worksheets("sheet1").Cells(data_row, g_col).Value
.Cells(z, 8).Value = Worksheets("sheet1").Cells(data_row, h_col).Value
.Cells(z, 9).Value = Worksheets("sheet1").Cells(data_row, i_col).Value
End With
z = z + 1
End Sub
อันนี้คือที่ทำไว้ครับ มัน search ได้แค่อันเดียวครับ search ทั้ง 3 อันไม่ได้ ต้องแก้อะไรบ้างครับ
