Hi,
I am attempting to create a table where costs can be calculated by the user. These are spread into different categories.
I have created a macro using relative reference and assigned this to a button which allows a new line to be entered into the table every time the button is pressed but this means a specific cell needs to be highlighted. My intention was to have the highlighted or referenced cell to be the one which the button is on. This way i can copy the button elsewhere and based on the relative reference it should create copies of the row above when clicked.
My knowledge of macros and VBA is very limited but the code is:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Sub Macro2()
'
' Macro2 Macro
'
'
ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Copy
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
ActiveCell.Offset(2, 6).Range("A1").Select
End Sub</code>
I guess ActiveCell should somehow refer to the Button cell instead.
UPDATE: i have attempted to use the code from some online forums below to help with my understanding. However, i seem to get an error:
Run-time error '1004':
Unable to get the Buttons property pf the worksheet class
Any ideas?
Thanks.
I am attempting to create a table where costs can be calculated by the user. These are spread into different categories.
I have created a macro using relative reference and assigned this to a button which allows a new line to be entered into the table every time the button is pressed but this means a specific cell needs to be highlighted. My intention was to have the highlighted or referenced cell to be the one which the button is on. This way i can copy the button elsewhere and based on the relative reference it should create copies of the row above when clicked.
My knowledge of macros and VBA is very limited but the code is:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Sub Macro2()
'
' Macro2 Macro
'
'
ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Copy
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
ActiveCell.Offset(2, 6).Range("A1").Select
End Sub</code>
I guess ActiveCell should somehow refer to the Button cell instead.
UPDATE: i have attempted to use the code from some online forums below to help with my understanding. However, i seem to get an error:
Run-time error '1004':
Unable to get the Buttons property pf the worksheet class
Code:
[COLOR=#141414][FONT="]Public Sub Button_Click()[/FONT][/COLOR]
[COLOR=#141414][FONT="]With ActiveSheet.Buttons(Application.Caller)[/FONT][/COLOR]
[COLOR=#141414][FONT="]Cells(.TopLeftCell.Row, .BottomRightCell.Column + 1).Value = "X"[/FONT][/COLOR]
[COLOR=#141414][FONT="]End With[/FONT][/COLOR]
[COLOR=#141414][FONT="]End Sub[/FONT][/COLOR]
Any ideas?
Thanks.