我試圖讓一個Excel宏工作,但我有一個問題,從包含公式的單元格複製值。複製範圍和粘貼值在另一個工作表的特定範圍
到目前爲止,這是我的,它與非公式單元格工作正常。
Sub Get_Data()
Dim lastrow As Long
lastrow = Sheets("DB").Range("A65536").End(xlUp).Row + 1
Range("B3:B65536").Copy Destination:=Sheets("DB").Range("B" & lastrow)
Range("C3:C65536").Copy Destination:=Sheets("DB").Range("A" & lastrow)
Range("D3:D65536").Copy Destination:=Sheets("DB").Range("C" & lastrow)
Range("E3:E65536").Copy Destination:=Sheets("DB").Range("P" & lastrow)
Range("F3:F65536").Copy Destination:=Sheets("DB").Range("D" & lastrow)
Range("AH3:AH65536").Copy Destination:=Sheets("DB").Range("E" & lastrow)
Range("AIH3:AI65536").Copy Destination:=Sheets("DB").Range("G" & lastrow)
Range("AJ3:AJ65536").Copy Destination:=Sheets("DB").Range("F" & lastrow)
Range("J3:J65536").Copy Destination:=Sheets("DB").Range("H" & lastrow)
Range("P3:P65550").Copy Destination:=Sheets("DB").Range("I" & lastrow)
Range("AF3:AF65536").Copy Destination:=Sheets("DB").Range("J" & lastrow).
End Sub
我怎樣才能讓它粘貼值呢?
如果這可以改變/優化,我也會很感激。
謝謝您的回覆。我嘗試使用數組的第一個代碼,並且出現「腳本超出範圍」的錯誤,並且在將表格(「Sheet1」)更改爲「DB」後,它只是沒有做任何事情。就像FYI一樣,我正在使用Excel 2010.我還沒有嘗試過其他選項。有什麼建議麼? – BlueSun3k1
我也糾正了這部分。 >> arr1 = Array(「B」,「C」,「D」,「E」,「F」,「AH」,「AIH」,「AJ」,「J」,「P」,「AF」) 「從AIH到AI並且這個固定的,仍然有同樣的錯誤。 – BlueSun3k1
你應該將'Sheet1'換成'With With Sheets(Sheet1)''到你正在處理數據的表格名稱_from。例如。如果將表單'mySheet'中的數據複製到'DB'表單中,則應將'Sheet1'(與'Sheets(「Sheet1」)')一致更改爲'mySheet'。如果您想從_active sheet_中複製,請將'With Sheets(「Sheet1」)'改爲'With ActiveSheet'(它會將當前活動工作表中的數據複製到'DB'工作表中) –