[英]Copy cell that equals cell value from another worksheet
我有 3 個工作表:工作表 A、B 和 C。
工作表 B 具有從工作表 A 中提取信息並以特定視覺格式放置的單元格。
然后我更改工作表 B 上單元格的顏色(值等於工作表 A 的相同單元格)並嘗試將值和顏色復制到工作表 3 中的一列。
Sub copycellcolor1()
Dim rField As Range
Dim idCell As Range
Dim r1WS As Worksheet
Dim rrWS As Worksheet
Set r1WS = Worksheets("RACK 1")
Set rField = r1WS.Range("C6:N13")
Set rrWS = Worksheets("Reruns To Pull")
For Each idCell In rField
If idCell.Interior.color = RGB(204, 204, 255) Then
idCell.Copy rrWS.Range("A1").Offset(rrWS.Rows.Count - 1, 0).End(xlUp).Offset(1, 0)
End If
Next idCell
rrWS.Columns.AutoFit
End Sub
我在工作表 3 上得到了正確的顏色,但值為#REF!
因為單元格的實際值是指工作表 A。
有人可以解釋一下我做錯了什么嗎?
您使用錯誤的方式來復制/粘貼。 請嘗試以下操作:
If idCell.Interior.Color = RGB(204, 204, 255) Then
With rrWS.Range("A1").Offset(rrWS.Rows.Count - 1, 0).End(xlUp).Offset(1, 0)
idCell.Copy
' Paste values.
.PasteSpecial xlPasteValues
' Paste formats.
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
End If
' This is a little bit ridiculous, but it works.
If idCell.Interior.Color = RGB(204, 204, 255) Then
With rrWS.Range("A1").Offset(rrWS.Rows.Count - 1, 0).End(xlUp).Offset(1, 0)
' Paste values.
.Value = idCell.Value
' Paste formats.
idCell.Copy
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.