【发布时间】:2020-08-31 15:51:37
【问题描述】:
我目前正在研究数据集的宏。宏需要在 A 列中找到字符串“page”的行,然后将 worksheet(3) 中的另一个值粘贴到 M 列并与“page”在同一行中。我已经有一些来自上一个问题Find, select, and copy row 的代码,但我不知道如何指定我要粘贴到列 M 和与字符串相同的行中。
这是我所拥有的:
With ThisWorkbook
Set wsSource = .Worksheets("Overview")
Set wsDestination = .Worksheets("Overview")
End With
'Set the value you want to search
strSearch = "*Page*"
'Set the column you want to seach
ColumnNo = 1
'Create a with statement to point Sheet1.
With wsSource
'Search for strSearch in column number ColumnNo
Set rngFound = .Columns(ColumnNo).Find(strSearch, LookIn:=xlValues, lookat:=xlWhole)
If Not rngFound Is Nothing Then
LastRow = wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row + 1
'Copy row.
.Rows(rngFound.Row).EntireRow.Copy
'Paste row
wsDestination.Rows(LastRow).PasteSpecial Paste:=xlPasteValues
'Delete row
.Rows(rngFound.Row).EntireRow.Delete Shift:=xlUp
End If
End With
我现在需要调整上面指定的代码。有人可以帮我吗? 提前致谢
【问题讨论】:
-
有问题的单元格将是
wsDestination.Range("M" & rngFound.Row)。