2017-09-20 36 views
0

我有兩個excel文件; File_1和File_2。 File_1有兩張紙; Sheet_A和Sheet_B。來自File_2的數據轉換爲Sheet_A(在File_1中)。沒有鏈接到原始工作表的Excel VBA複印頁

我有一個vba代碼附加到Sheet_B中的一個按鈕,它將Sheet_A中的數據複製到Sheet_B中。代碼工作正常,但它保留了File_1的鏈接。

我想複製數據並保留其格式而不保留鏈接。我怎樣才能做到這一點?

我的代碼的一部分複製從Sheet_A數據到Sheet_B低於:我認爲你需要的值粘貼在目標

' Check the Record Sheet to ensure the data is not already there 
    Set CheckForDups = recordSht.Range(recordSht.Cells(1, 1), recordSht.Cells(1, lCol)).Find(What:=maxCustomerRng.Offset(-1, 0).Value, LookIn:=xlValues) 

    ' If CheckForDups is Nothing then the date was not found on the record sheet. Therefore, copy the column 
    If CheckForDups Is Nothing Then maxCustomerRng.EntireColumn.Copy Before:=recordSht.Cells(1, lCol + 1) 
+0

之間的文字和代碼提供,情況很不清楚。 –

+0

@ScottHoltzman我編輯了我的帖子。希望現在有意義。 – aab

回答

0

If CheckForDups Is Nothing Then 
    maxCustomerRng.EntireColumn.Copy 
    recordSht.Cells(1, lCol + 1).PasteSpecial xlPasteValues 
    recordSht.Cells(1, lCol + 1).PasteSpecial xlPasteFormats 
End If 

希望這有助於。

+0

感謝它的工作,但它不保留格式。 – aab

+0

'xlPasteValuesAndFormats' - 我認爲是常數。或者添加一行'recordSht.Cells(1,lCol + 1).PasteSpecial xlPasteFormats' –

+0

@ScottHoltzman是對的。請添加一行:recordSht.Cells(1,lCol + 1).PasteSpecial xlPasteFormats –

相關問題