Hello guys, first time posting here (an first time posting in a forum ever).
I'm desperate.
I am programming an Excel File to act as a game interface (a very simple one, for a gamification project in my company).
The thing is that I want to create an ActiveX button (why an ActiveX and not a Form? Because I can change the background of an ActiveX button and put an image in it) that operates the cell to the left of it, so I can copy the button in different rows and the button won't operate a fixed cell, but the cell next to it. I want to button to substract 1 to the cell on the left.
I've tried to program first a FORM control button (through a macro) with this code, and it works perfect:
Sub Substract()
Dim cellAddr As String
Dim aCol As Long
'~~> Get the address of the cell
cellAddr = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address
ActiveSheet.Range(cellAddr).Offset(, -3).Value = ActiveSheet.Range(cellAddr).Offset(, -3).Value - 1
End Sub
But I don't want a form control button, I want an ActiveX control button. I've tried this (calling the macro), but it does not work:
Private Sub CommandButton1_Click()
Substract
End Sub
When I click the button, this message appears: Run-time error '-2147352571 (80020005)': The item with the specified name wasn't found. And then, when I click on "debug", the VBA window highlights in yellow the following part of my macro:
Sub Substract()
Dim cellAddr As String
Dim aCol As Long
'~~> Get the address of the cell
cellAddr = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address
ActiveSheet.Range(cellAddr).Offset(, -3).Value = ActiveSheet.Range(cellAddr).Offset(, -3).Value - 1
End Sub
I've also tried copying the macro coding directly to the Private Sub of the ActiveX button, but it doesn't work either (same error as mentioned before):
Private Sub CommandButton1_Click()
Dim cellAddr As String
Dim aCol As Long
'~~> Get the address of the cell
cellAddr = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address
ActiveSheet.Range(cellAddr).Offset(, -3).Value = ActiveSheet.Range(cellAddr).Offset(, -3).Value - 1
End Sub
I would really appreciate some help on this because I have to submit this Excel by the end of today and this is the last thing left to do...
left Hope I'll be hearing from you.
Best Regards,
Chuck.
I'm desperate.
I am programming an Excel File to act as a game interface (a very simple one, for a gamification project in my company).
The thing is that I want to create an ActiveX button (why an ActiveX and not a Form? Because I can change the background of an ActiveX button and put an image in it) that operates the cell to the left of it, so I can copy the button in different rows and the button won't operate a fixed cell, but the cell next to it. I want to button to substract 1 to the cell on the left.
I've tried to program first a FORM control button (through a macro) with this code, and it works perfect:
Sub Substract()
Dim cellAddr As String
Dim aCol As Long
'~~> Get the address of the cell
cellAddr = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address
ActiveSheet.Range(cellAddr).Offset(, -3).Value = ActiveSheet.Range(cellAddr).Offset(, -3).Value - 1
End Sub
But I don't want a form control button, I want an ActiveX control button. I've tried this (calling the macro), but it does not work:
Private Sub CommandButton1_Click()
Substract
End Sub
When I click the button, this message appears: Run-time error '-2147352571 (80020005)': The item with the specified name wasn't found. And then, when I click on "debug", the VBA window highlights in yellow the following part of my macro:
Sub Substract()
Dim cellAddr As String
Dim aCol As Long
'~~> Get the address of the cell
cellAddr = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address
ActiveSheet.Range(cellAddr).Offset(, -3).Value = ActiveSheet.Range(cellAddr).Offset(, -3).Value - 1
End Sub
I've also tried copying the macro coding directly to the Private Sub of the ActiveX button, but it doesn't work either (same error as mentioned before):
Private Sub CommandButton1_Click()
Dim cellAddr As String
Dim aCol As Long
'~~> Get the address of the cell
cellAddr = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address
ActiveSheet.Range(cellAddr).Offset(, -3).Value = ActiveSheet.Range(cellAddr).Offset(, -3).Value - 1
End Sub
I would really appreciate some help on this because I have to submit this Excel by the end of today and this is the last thing left to do...
left Hope I'll be hearing from you.
Best Regards,
Chuck.