Sub searchdata()
Dim erow As Long
Dim ws As Worksheet
Dim lastrow As Long
Dim count As Integer
lastrow = Sheets("Data").Cells(Rows.count, 1).End(xlUp).Row
For x = 2 To lastrow
If Sheets("Data").Cells(x, 2) = Sheet2.Range("B3") Then
Sheet2.Range("A11") = Sheets("Data").Cells(x, 1)
Sheet2.Range("B11") = Sheets("Data").Cells(x, 2)
count = count + 1
End If
If Sheets("Data").Cells(x, 3) = Sheet2.Range("B3") Then
Sheet2.Range("A11") = Sheets("Data").Cells(x, 1)
Sheet2.Range("C11") = Sheets("Data").Cells(x, 3)
count = count + 1
End If
Next x
If count = 0 Then
Set ws = Worksheets("sheet3")
erow = ws.Cells(Rows.count, 1).End(xlUp).Offset(1, 0).Row
Sheet2.Range("A11:C11").ClearContents
End If
End Sub
答案 0 :(得分:0)
位
Sheet2.Range("A11") = Sheets("Data").Cells(x, 1)
Sheet2.Range("C11") = Sheets("Data").Cells(x, 2)
Sheet2.Range("C11") = Sheets("Data").Cells(x, 3)
位于循环内部,因此每次都会不断覆盖。不知道你想做什么,但这看起来毫无意义。