Usva
Computer
- Jun 4, 2004
- 2
I havent used exel too much and even less VB, so my current code might be a bit messy as im building it bit by bit.
Anyways Im trying to make a button that creates a sheet, copies stuff from another sheet and pastes it in the new one, creates a button that takes user from the new sheet back to where the original creation button is and creates new row on that page and button that takes the user from that row to the created page.
Problem is that Im not really sure how to get the name of created sheet to the button on another sheet automatically. Below is the code and the last row is prolly where the problem is. This code doesnt yet have any dynamic position features or such and its just a test untill I get it working properly and then ill be able to use it on the actual excel workbook.
Private Sub CommandButton1_Click()
Sheets("kopioitava").Select
ActiveCell.Range("A1:E8").Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste
ActiveSheet.Buttons.Add(48, 153, 96, 26.25).Select
Selection.OnAction = "Painike2_Napsautettaessa"
Dim nimi As String
nimi = ActiveSheet.Name
Sheets("toiminnot").Select
ActiveSheet.Buttons.Add(115.5, 221.25, 117, 44.25).Select
Selection.OnAction = Sheets("nimi").Select
End Sub
That code has some finnish words, if u were wondering what they ment. So anyways the last row before End Sub is where the problem is. Its supposed to tell the new button that when its clicked it should take the user to sheet that has the freshly created sheets name. Could someone tell me how to do it right? Currently it doesnt work.
Anyways Im trying to make a button that creates a sheet, copies stuff from another sheet and pastes it in the new one, creates a button that takes user from the new sheet back to where the original creation button is and creates new row on that page and button that takes the user from that row to the created page.
Problem is that Im not really sure how to get the name of created sheet to the button on another sheet automatically. Below is the code and the last row is prolly where the problem is. This code doesnt yet have any dynamic position features or such and its just a test untill I get it working properly and then ill be able to use it on the actual excel workbook.
Private Sub CommandButton1_Click()
Sheets("kopioitava").Select
ActiveCell.Range("A1:E8").Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste
ActiveSheet.Buttons.Add(48, 153, 96, 26.25).Select
Selection.OnAction = "Painike2_Napsautettaessa"
Dim nimi As String
nimi = ActiveSheet.Name
Sheets("toiminnot").Select
ActiveSheet.Buttons.Add(115.5, 221.25, 117, 44.25).Select
Selection.OnAction = Sheets("nimi").Select
End Sub
That code has some finnish words, if u were wondering what they ment. So anyways the last row before End Sub is where the problem is. Its supposed to tell the new button that when its clicked it should take the user to sheet that has the freshly created sheets name. Could someone tell me how to do it right? Currently it doesnt work.