[英]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.