2014-03-26 20 views
0

在我的Excel VBA代碼中,我不想從表單中複製Calculatie到表單甘特圖,但是當我「 t粘貼到甘特圖表單元格中,我得到一個錯誤。見下面的代碼。繼續收到應用程序定義或對象定義的錯誤,雖然我看不出我做錯了什麼

請注意,我使用「測試」變量,看看我能否以其他方式工作。

Sub setValue() 
Dim test As String 

gantCell = Sheets("Gantt Chart").Rows("5:1000").SpecialCells(xlCellTypeVisible).Row 
calcCell = gantCell - 3 
formCell = gantCell + 1 
Worksheets("Gantt Chart").Cells(gantCell, 6).Value = "1" 
gantCellNext = Sheets("Gantt Chart").Rows("5:1000").SpecialCells(xlCellTypeVisible).Row 
'code zoeken om alle cellen onder de 1e zichtbare cell de volgende formule te geven =rij 1 hoger dan de huidige cel + 1 rij en 1 kollum hoger 
i = gantCell 
test = "F" & i 
MsgBox test 
Sheets("Calculatie").Cells(calcCell, 2).Copy 
Sheets("Gantt Chart").Range("test: F35").PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationMultiply 
MsgBox formCell 
MsgBox gantCell 
MsgBox calcCell 

End Sub 
+0

變化'範圍( 「測試:F35」)'來'範圍(測試&「: F35「)'或簡單地使用'範圍(測試).PasteSpecial ...' –

+0

工作!非常感謝!設置這個問題來解決。 – Gilmoo

回答

1

由於從評論跟進,這一個工程:

Sheets("Gantt Chart").Range(test).PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationMultiply 

Sheets("Gantt Chart").Range(test & ":F35").PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationMultiply 
+1

再次感謝! ;) – Gilmoo

相關問題