2017-09-08 147 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) 

這應該做的伎倆。

相關問題