2017-03-06 75 views
0

我更喜歡使用函數.value,因爲我不會錯過任何東西,但我不能粘貼或全部範圍我不能在其他工作表中「拼湊」日期「放」! (複製和粘貼)

任何人都知道我能做些什麼?

Sub AUTO() 


Application.ScreenUpdating = False 

'sheet that i want paste 
PasteData1 = ActiveSheet.Cells(3, 6).Value 
DATAAUTO = "L:\ANALISTA_M\Frade\FINANCIAL SERVICES\INSURANCE\Mercado\SUSEP\Planilhas\Auto-Susep.xlsx" 
Workbooks.Open (DATAAUTO) 
sName = ActiveSheet.Name 

'count the number of rows and columns 
i = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row - 11 
c = ActiveSheet.Cells(6, Columns.Count).End(xlToLeft).Column 

'select all range that i want 
COPYDATE = ActiveSheet.Range(Cells(6, 1), Cells(i, c)).Value 


PASTEAUTO = "L:\ANALISTA_M\Frade\FINANCIAL SERVICES\INSURANCE\Mercado\SUSEP\Auto.xlsm" 
Workbooks.Open (PASTEAUTO) 
Worksheets(PasteData1).Activate 

'the problem is here!!! i need to respect a order the beging my paste 
ActiveSheet.Cells(2, 2).Value = COPYDATE 

ActiveSheet.Range(Cells(2, 2), Cells(i - 4, c + 1)).Replace What:=".", Replacement:="" 
ActiveSheet.Range(Cells(2, 2), Cells(i - 4, c + 1)).Replace What:=",", Replacement:="." 

Worksheets("Consolidado").Activate 

Workbooks("Auto-Susep.xlsx").Close 

Application.ScreenUpdating = True 

End Sub 

回答

1

使用.Value在複製粘貼,你需要有相同的尺寸範圍。你有一個單元格試圖容納一個2維數組。

因此改變:

ActiveSheet.Cells(2, 2).Value = COPYDATE 

到:

ActiveSheet.Cells(2, 2).Resize(UBound(COPYDATE,1),UBound(COPYDATE,2)).Value = COPYDATE 

此外,我不看,你聲明你的任何變量,這是一個不好的習慣,人們總是應該即使申報變數它們是變體類型。

Dim COPYDATE() as Variant 
+0

感謝SCOOT 這是確定 – Vinicius

+0

一兩件事,斯科特 我很好奇。我不明白爲什麼聲明變量非常重要,因爲即使我沒有聲明,代碼也能正常工作 – Vinicius

相關問題