Sub find_K_in_C2I()
Dim arr()
Sheets("工作表1").Select
Rcnt = [a1].End(xlDown).Row
Ccnt = [a1].End(xlToRight).Column
ReDim arr(1 To Rcnt)
arr(1) = 1
For i = 2 To Rcnt
arr(i) = Application.CountIf(Range(Cells(i, 3), Cells(i, Ccnt)), "K")
Next i
k = 1
For i = 1 To Rcnt
If arr(i) > 0 Then
Sheets("工作表2").Cells(k, 1).Resize(1, Ccnt) = Sheets("工作表1").Cells(i, 1).Resize(1, Ccnt).Value
k = k + 1
End If
Next i
End Sub
問題描述提到 舉例在工作表1的C到I欄中搜尋"K"隊 但是根據上述例子應該是J欄
這列 1 主 種 1 2 3 4 5 6 7 應該不會被抓到工作表2但我看你結果有抓
所以我就預設放到工作表2最上面
跑出來的結果參考及檔案如下
https://c-t.work/s/7d7836a5d05144
應該可以滿足您的需求
Sub test()
Dim i As Integer
Dim j As Integer
Dim start_row As Integer
'直欄迴圈(由上而下)
For i = 1 To Sheets(1).Range("A65536").End(xlUp).Row
'橫列迴圈從(C欄開始 由左至右)
For j = 3 To 10
'有出現K則COPY到Sheet2 並跳出橫列迴圈
If Sheets(1).Cells(i, j) = "K" Then
'Sheet2目的位置
start_row = Sheets(2).Range("A65536").End(xlUp).Row + 1
Sheets(1).Rows(i).Copy Sheets(2).Range("A" & start_row)
Sheets(2).Range("A" & start_row) = start_row
Exit For
End If
Next
Next
End Sub