我的代碼嘗試執行此操作并粘貼在最后一行下方
Sub btnFind_Click()
Dim strLastRow As String
Dim rngC As Range
Dim strToFind As String, FirstAddress As String
Dim wSht As Worksheet
Dim rngtest As String
Application.ScreenUpdating = False
Set wSht = Worksheets("NewS")
strToFind = InputBox("Enter the value to find")
With ActiveSheet.Range("A1:A121")
Set rngC = .Find(what:=strToFind, LookAt:=xlPart)
If Not rngC Is Nothing Then
FirstAddress = rngC.Address
Do
strLastRow = Worksheets("NewS").Range("A" & Rows.Count).End(xlUp).Row 1
rngC.EntireRow.Copy wSht.Cells(strLastRow, 1)
Set rngC = .FindNext(rngC)
Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress
End If
End With
MsgBox ("Finished")
End Sub
結果粘貼在活動作業表的最后一行下方,但我希望將結果粘貼在第 N3 列作為開始,而且我不希望粘貼實際字串(僅該行中剩余的列值)。
如下圖,我選擇了值 2 作為字串。

uj5u.com熱心網友回復:
嘗試這個:
Sub btnFind_Click()
Dim rngC As Range, rngDest As Range
Dim strToFind As String, FirstAddress As String
Dim wSht As Worksheet
Dim rngtest As String
Application.ScreenUpdating = False
Set wSht = Worksheets("NewS")
strToFind = InputBox("Enter the value to find")
Set rngDest = wSht.Range("N3") 'start pasting here
With wSht.Range("A1:A121")
Set rngC = .Find(what:=strToFind, LookAt:=xlPart)
If Not rngC Is Nothing Then
FirstAddress = rngC.Address
Do
rngC.Offset(0, 1).Resize(1, 10).Copy rngDest 'move one cell right and copy 10 cols
Set rngDest = rngDest.Offset(1, 0) 'next destination row
Set rngC = .FindNext(rngC)
Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress
End If
End With
MsgBox "Finished"
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/338008.html
上一篇:如何停止ASP.NET回發(回傳false、e.stopPropagation、e.cancelBubble)不起作用
