T
Tanya
Hi I have a macro in my workbook which appears to be activated whenever data
changes. For example, if I delete a piece of data or paste data.
Here is the error:
Run-time error '13'
Type Mismatch
choose [End] or [Debug]
I have been choosing 'End' as a solution, but it is becoming annoying. Below
is a copy of my code which comes up when you choose 'Debug'. If any one could
help I would be very grateful.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Const BUTTON_COUNT = 10
Const SHEET_WITH_BUTTONS = "Setup"
Dim ButtonDefs() As Variant
ReDim ButtonDefs(0 To BUTTON_COUNT - 1)
' START OF BUTTON DEFINITIONS
'Each array is three strings:
'Name of change sheet, change cell address, associated button name
ButtonDefs(0) = Array("1", "B1", "CommandButton1")
ButtonDefs(1) = Array("2", "B1", "CommandButton2")
ButtonDefs(2) = Array("3", "B1", "CommandButton3")
ButtonDefs(3) = Array("4", "B1", "CommandButton4")
ButtonDefs(4) = Array("5", "B1", "CommandButton5")
ButtonDefs(5) = Array("6", "B1", "CommandButton6")
ButtonDefs(6) = Array("7", "B1", "CommandButton7")
ButtonDefs(7) = Array("8", "B1", "CommandButton8")
ButtonDefs(8) = Array("9", "B1", "CommandButton9")
ButtonDefs(9) = Array("10", "B1", "CommandButton10")
'
'...CONTINUE THESE DEFINITIONS AS NEEDED...
' END OF BUTTON DEFINITIONS
Dim arr As Variant
For Each arr In ButtonDefs
'NOTE: the following assumes Option Base 0 (the default)
swcc = arr(0) 'sheet with change cell
cca = arr(1) 'change cell address
bn = arr(2) 'button name
If StrComp(Sh.Name, swcc, vbTextCompare) = 0 Then
If Target = Me.Worksheets(swcc).Range(cca) Then
Me.Worksheets(SHEET_WITH_BUTTONS).OLEObjects(bn). _
Object.Caption = Target.Text
End If
End If
Next
End Sub
Kind Regards
Tanya
changes. For example, if I delete a piece of data or paste data.
Here is the error:
Run-time error '13'
Type Mismatch
choose [End] or [Debug]
I have been choosing 'End' as a solution, but it is becoming annoying. Below
is a copy of my code which comes up when you choose 'Debug'. If any one could
help I would be very grateful.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Const BUTTON_COUNT = 10
Const SHEET_WITH_BUTTONS = "Setup"
Dim ButtonDefs() As Variant
ReDim ButtonDefs(0 To BUTTON_COUNT - 1)
' START OF BUTTON DEFINITIONS
'Each array is three strings:
'Name of change sheet, change cell address, associated button name
ButtonDefs(0) = Array("1", "B1", "CommandButton1")
ButtonDefs(1) = Array("2", "B1", "CommandButton2")
ButtonDefs(2) = Array("3", "B1", "CommandButton3")
ButtonDefs(3) = Array("4", "B1", "CommandButton4")
ButtonDefs(4) = Array("5", "B1", "CommandButton5")
ButtonDefs(5) = Array("6", "B1", "CommandButton6")
ButtonDefs(6) = Array("7", "B1", "CommandButton7")
ButtonDefs(7) = Array("8", "B1", "CommandButton8")
ButtonDefs(8) = Array("9", "B1", "CommandButton9")
ButtonDefs(9) = Array("10", "B1", "CommandButton10")
'
'...CONTINUE THESE DEFINITIONS AS NEEDED...
' END OF BUTTON DEFINITIONS
Dim arr As Variant
For Each arr In ButtonDefs
'NOTE: the following assumes Option Base 0 (the default)
swcc = arr(0) 'sheet with change cell
cca = arr(1) 'change cell address
bn = arr(2) 'button name
If StrComp(Sh.Name, swcc, vbTextCompare) = 0 Then
If Target = Me.Worksheets(swcc).Range(cca) Then
Me.Worksheets(SHEET_WITH_BUTTONS).OLEObjects(bn). _
Object.Caption = Target.Text
End If
End If
Next
End Sub
Kind Regards
Tanya