简体   繁体   English

满足条件时,将仅行的一部分复制粘贴到另一张纸上,其中一个单元格包含图片

[英]Copy paste only part of rows, with one cell containing a picture, on another sheet when condition is met

I have a worksheet named Data where I listed products in rows. 我有一个名为Data的工作表,其中我在行中列出了产品。 The information for each product are in columns A:W. 每个产品的信息都在A:W列中。 The column A is used for companies ID. A列用于公司ID。 Depends on the ID selected in a dropdown list, I want the cells P:W to be pasted in a worksheet named Quote starting from row 11 in columns A:H. 根据下拉列表中选择的ID,我希望将单元格P:W粘贴到名为Quote的工作表中,该工作表从A:H列的第11行开始。 It must be noted the column W in the worksheet Data is used for pictures. 必须注意,工作表数据中的W列用于图片。

I found some codes over the Web and tried to adapt it to my case with no success. 我在网上找到了一些代码,并试图使其适应我的情况,但没有成功。 First, I cannot copy paste the pictures. 首先,我无法复制粘贴图片。 I assume I should use the Range.Copy method instead of PasteSpecial method, but I cannot make it works in my code. 我假设我应该使用Range.Copy方法而不是PasteSpecial方法,但是我无法使其在我的代码中起作用。 Second, I could not find a proper way to copy and paste only the cells from columns P:W. 其次,我找不到仅复制和粘贴P:W列中的单元格的正确方法。

Sub Quote()

Dim Data As Worksheet
Dim Quote As Worksheet
Dim CompanyID As String
Dim Finalrow As Integer
Dim i As Integer

Set Data = Sheet3
Set Quote = Sheet2
CompanyID = Sheet6.Range("E5").Value

Data.Select
Finalrow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To Finalrow
    If Cells(i, 1) = CompanyID Then
    Range(Cells(i, 1), Cells(i, 23)).Copy
    Quote.Select
    Rows(11).Select
    Range("A200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
    Data.Select
    End If

Next i

Quote.Select
Range("A11:O200").Delete
Range("A1").Select

End Sub

Try 尝试

Data.Range(Cells(i, 16), Cells(i, 23)).Copy Quote.Range("A200").End(xlUp).Offset(1, 0).resize(1,8)

You can delete all the .Select rows in your code. 您可以删除代码中的所有.Select行。 In Excel automation .Select is almost never necessary. 在Excel自动化.Select是几乎从来没有必要的。 Also you have already referenced the worksheets. 另外,您已经参考了工作表。 If you use those references in determining the range, you won't have to go to the sheets. 如果使用这些参考来确定范围,则不必翻页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 满足条件时将各种单元格复制并粘贴到另一个工作表 - Copy and Paste various cells to another sheet when condition met 满足条件时,Excel VBA 从一张纸到另一张纸的复制粘贴循环 - Excel VBA copy paste loop from one sheet to another when condition is met 在满足条件的情况下将单元格复制到另一个工作表 - Copy Cell to another sheet in condition is met Loop 如果满足条件,则将单元格复制到另一张工作表 - Copy cell to another sheet if condition is met 动态满足条件时将数据从一张表复制到另一张表 - Copy data from one sheet to another when condition is met dynamically 将一张图片从一张纸复制并粘贴到另一张纸上 - copy & paste a picture from one sheet to another 从另一张纸上的单元格值复制同一张纸中范围的一部分的粘贴范围 - Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet 如果条件满足,如何复制单元格并粘贴到另一个单元格中? - How to copy cell if condition is met and paste in another cell? 如果满足两个范围标准,请复制第三个单元格并将其粘贴到另一张纸上 - If two range criteria are met, copy a third cell and paste it to another sheet 根据单元格colorindex从一个工作表的粘贴范围复制范围到另一工作表的另一工作表 - Copy Range From One Sheet Paste Part of Range In another Sheet Based On Cell colorindex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM