2017-09-08 146 views
-1

我之前已收到此代码的很好帮助。 如果列C中的单元格包含值列表(值为1,值为2,值为3,值为4),它将从列A到列D中的公式以及从列B到列E中的值复制。当另一个单元格包含特定值时,复制单元格值和单元格注释

我现在需要从B列跨单元格批注以及细胞值也复制到列E.

有谁知道我怎么能做到这一点?

Sub RangeCopyPaste() 

Dim cell As Range 

Range("D6:E1000").Clear 

Set OcRange = Range("D6") 'Set the first destination cell 

For Each cell In Worksheets("OverviewTest").Range("C6:C1000") 'Loop through your Status column 
    Select Case cell.Value 'Select Case is an alternative to writing multiple If, ElseIf statements, particularly if you want it to run the same code when it is true. 
     Case "Value1", "Value2", "Value3", "Value4" 'Specify all the values which would consitute a "True" result 
      OcRange.Formula = Range(cell.Offset(0, -2), cell.Offset(0, -2)).Formula 'Copies the formula from Column A 
      OcRange.Offset(0, 1).Value = Range(cell.Offset(0, -1), cell.Offset(0, -1)).Value ' Copies the value from Column B 
      Set OcRange = OcRange.Offset(1, 0) 'Setup the new destination cell ready for the next "True" result 
    End Select 
Next cell 

End Sub 
+1

你必须显示你的一些努力。你在网上看过吗?你有什么发现/尝试过? – CallumDA

+1

请阅读[*为什么“有人可以帮我吗?”不是一个真正的问题?*](https://meta.stackoverflow.com/q/284236/1188513) –

+0

您已经有代码将值从B复制到E ....只需添加代码复制评论....你必须弄清楚自己 – jsotola

回答

0

替换此:

OcRange.Formula = Range(cell.Offset(0, -2), cell.Offset(0, -2)).Formula 
OcRange.Offset(0, 1).Value = Range(cell.Offset(0, -1), cell.Offset(0, -1)).Value 

有了这个:

Range(cell.Offset(0, -2), cell.Offset(0, -2)).Copy 
OcRange.PasteSpecial (xlPasteFormulas) 
OcRange.PasteSpecial (xlPasteComments) 

Range(cell.Offset(0, -1), cell.Offset(0, -1)).Copy 
OcRange.Offset(0, 1).PasteSpecial (xlPasteValues) 
OcRange.Offset(0, 1).PasteSpecial (xlPasteComments) 

这应该做的伎俩。

相关问题