查找特定数据并复制内容直到行结束

时间:2015-11-23 08:54:22

标签: excel vba excel-vba copy find

我分别维护了两份Excel报告EPC1.xlsxControl Power Transformers.xlsm

我想触发Control Power Transformers.xlsm报告中的按钮点击,它会在" A"中搜索"CTPT"字词。来自EPC1.xlsx的列,一旦找到需要复制列B和列c的行,直到该行结束(在EPC1.xlsx中)并将其粘贴到Control Power Transformers.xlsm工作簿中

我成功地检索了" CTPT"的细胞地址。术语,但如何选择相邻列B和C的数据?

enter image description here

这就是我试过的

Private Sub CommandButton23_Click()
Dim rngX As Range
Dim num As String

Windows("EPC 1.xlsx").Activate
Set rngX = Worksheets("Sheet1").Range("A1:A10000").Find("CTPT", Lookat:=xlPart)
num = rngX.Address ' Here we will the get the cell address of CTPT ($A$14)
Range(rngX, Range("C" & rngX.Row).End(xlDown)).Copy
Windows("Control Power Transformers.xlsm").Activate
Sheets("Sheet2").Select
ActiveSheet.Range("E2").PasteSpecial (xlPasteValues)


End Sub

0 个答案:

没有答案