在其他工作簿的其他工作表中查找值并复制到当前工作簿的工作表

发布于 2024-12-11 21:51:10 字数 1246 浏览 0 评论 0原文

我在两本不同的工作簿中有两张纸。 a) 工作簿(A).Sheets("A") b)Workbook(B).Sheets("B")

工作簿A中的工作表A是目标文件。 工作簿 B 中的工作表 B 是源文件。

用户在工作表A中输入B的文件名(打开工作表B),然后从工作表B中循环查找大于参考值的值。找到值后,该值将立即复制并粘贴到工作表 A(工作簿 b)中。然后在B表中循环查找后续值(大于参考值)。该过程将持续进行,直到满足某些标准。

我设法在循环中找到该值,但我必须将该值粘贴到工作表 B 中,然后复制到工作表 A 中。当然,用户必须单击是否保存工作表 B 的消息。 下面是写的代码。请赐教。

Dim VerR As Workbook
Dim VerRDest As Worksheet
Dim VerRMaxR As Range

Application.ScreenUpdating = False
XLS = Cells(16, 5)
Workbooks(XLS).Activate

Sheets("ROLLER").Select
Path = Cells(18, 5)
NoR = Cells(17, 5)
Workbooks.Open Filename:=Path

Set VerR = Workbooks(XLS)
Sheets("Stat_1").Select        
y = 3
i = 4
Do While (Cells(i, 1) <> "")
    i = i + 1
Loop

m2 = i - 1
For x = 4 To m2
    If (cells(x,2)>5) Then
        y = y + 1
        TF = True
        If TF Then
            Cells(y, 6) = Cells(x + 1, 1)
            Cells(y, 5) = Cells(x + 1, 2)
        End If
    End If
Next x

Set VerMax1 = ActiveSheet.Range(Cells(4, 5), Cells(y, 6))
VerMax1.Copy
ActiveWorkbook.Close

Set VerRDest = VerR.Worksheets("ROLLER")
Set VerRMaxR = VerRDest.Range(Cells(4, 3), Cells(y, 4))
VerRMaxR.PasteSpecial , Paste:=xlPasteValues

我的目标是粘贴该值而不影响源工作簿。请帮助。谢谢。我真的很欣赏你的想法。我已经无计可施了。

I have 2 sheets in 2 different work book.
a) Workbook(A).Sheets("A")
b)Workbook(B).Sheets("B")

Sheet A in workbook A is destination file.
Sheet B in Workbook B is source file.

User Input file name of B( to open sheet B) in sheet A, then from sheet B, it loops to find values which are larger than a reference value. With found value, the value will be copied and pasted to sheet A(workbook b) instantaneously . Then loop back in sheet B to find subsequent value(which is larger than reference value). The process continues until it meets certain criteria.

I manage to find the value in loop, but i have to paste the value into sheet B, then copy to sheet A. For sure, user has to click the message whether to save sheet B.
Below is the code written. Pls enlighten me.

Dim VerR As Workbook
Dim VerRDest As Worksheet
Dim VerRMaxR As Range

Application.ScreenUpdating = False
XLS = Cells(16, 5)
Workbooks(XLS).Activate

Sheets("ROLLER").Select
Path = Cells(18, 5)
NoR = Cells(17, 5)
Workbooks.Open Filename:=Path

Set VerR = Workbooks(XLS)
Sheets("Stat_1").Select        
y = 3
i = 4
Do While (Cells(i, 1) <> "")
    i = i + 1
Loop

m2 = i - 1
For x = 4 To m2
    If (cells(x,2)>5) Then
        y = y + 1
        TF = True
        If TF Then
            Cells(y, 6) = Cells(x + 1, 1)
            Cells(y, 5) = Cells(x + 1, 2)
        End If
    End If
Next x

Set VerMax1 = ActiveSheet.Range(Cells(4, 5), Cells(y, 6))
VerMax1.Copy
ActiveWorkbook.Close

Set VerRDest = VerR.Worksheets("ROLLER")
Set VerRMaxR = VerRDest.Range(Cells(4, 3), Cells(y, 4))
VerRMaxR.PasteSpecial , Paste:=xlPasteValues

My objective is to paste the value without affecting source workbook.Pls help. Thanks.I truly appreciate your idea.I am at my wits end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救赎№ 2024-12-18 21:51:10
dim r1 as range, r2 as range

r1.copy r2

或者

r1.copy
r2.pastespecial ....
dim r1 as range, r2 as range

r1.copy r2

or

r1.copy
r2.pastespecial ....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文