背景故事:我正在做一個小項目,幫助我的小團體幫助人們擁有清晰易懂的會計系統。 我是VBA的總新手,我一直在尋找一個簡單的解決方案,在論壇上沒有成功:/VBA Excel複製和粘貼模板
我的Excel文件基本上有兩個電源板。 Compta:在這裏我輸入數據 型號:模板
,我想要的結果,是當我按下「Compta」按鈕,它會生成與粘貼在它和名爲模板的新表是我已決定。
Sub lala()
'part one creating new sheet with "P21" the name of the sheet
Dim projname As Range
Set projname = Range("P21")
ActiveWorkbook.Sheets.Add Before:=Worksheets(Worksheets.Count)
ActiveSheet.Name = projname
'part two copying and pasting the template on the new sheet
Sheets("Model").Activate
ActiveSheet.Copy
'this is the line where my problem is residing
Worksheets(projname).Select
Selection.Paste
End Sub
我的問題是,當它執行我的第一部分進行得很順利,但部分2不會在所有複製的新表。它會生成一個帶有模板的新工作簿。
有沒有簡單的解決方案?我知道有一個,但我不能把它的手指放在它上面。
您想複製名爲「template」的工作表並創建一個新的工作表,並在其中包含數據,並將其命名爲Range(「P21」)?但在哪個表中存在Range(「P21」)?在「Compta」或「模板」中? –
無論如何,看看我的答案和下面的代碼,看看它是否按照你的意圖工作 –
是的值範圍(「P21」)來自Compta,我填寫所有的基本數據來個性化模板。代碼工作非常好,謝謝你 –