Hi All,
I am having a problem with getting a specific Macro to run when the text in a cell is changed to a corresponding value. What I would like is for a Macro to be ran on one worksheet (Report) when the value of a cell (A1) on another worksheet (CaseSelect) is changed.
The value of the cell is determined by a number of inputs from the first worksheet. As these inputs are changed I would like for the appropriate Macro to be called automatically. In total there are 15 possible values, for Cell 'A1' (ie. 'GP1BR1S'), based on the various inputs, and 15 corresponding Macros (ie. 'GP1BR1S').
below is the code I am trying to get to work.
When I change one of the inputs I get "Run-Time error '-2147417848 (80010108)': Method 'Range' of object '_Worksheet' failed"
When I debug this it highlights my second line of code, "If Sheets("CaseSelect").Range("$A$1").Value = "GP1BR1S" Then" as being the problem.
An interesting point to note is that it seems as though the Macro GP1BR1S is being called as some of the formatting is being changed, something that the Macro is supposed to do. However none of the other functions of the Macro are being ran.
All of the Macros do essentially the same thing, which is to clear the existing contents of certain cells, and then to replace the contents of those cells with the contents of another worksheet.
Below is an example of one of the Macros (GP1BR1S);
Thanks in advanced for any help you can give me. If you need me to give you more information about the code or the worksheets then just let me know. Also I'm fairly new to using VBA and would appreciate it if you could explain any answers you can provide, just to help me learn and understand.
Kind regards,
Connor
I am having a problem with getting a specific Macro to run when the text in a cell is changed to a corresponding value. What I would like is for a Macro to be ran on one worksheet (Report) when the value of a cell (A1) on another worksheet (CaseSelect) is changed.
The value of the cell is determined by a number of inputs from the first worksheet. As these inputs are changed I would like for the appropriate Macro to be called automatically. In total there are 15 possible values, for Cell 'A1' (ie. 'GP1BR1S'), based on the various inputs, and 15 corresponding Macros (ie. 'GP1BR1S').
below is the code I am trying to get to work.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheets("CaseSelect").Range("$A$1").Value = "GP1BR1S" Then
Call GP1BR1S
ElseIf Sheets("CaseSelect").Range("A1") = "GP2BR1S" Then
Call GP2BR1S
ElseIf Sheets("CaseSelect").Range("A1") = "GP3BR1S" Then
Call GP3BR1S
ElseIf Sheets("CaseSelect").Range("A1") = "GP1BR1SA" Then
Call GP1BR1S
ElseIf Sheets("CaseSelect").Range("A1") = "GP2BR1SA" Then
Call GP2BR1S
ElseIf Sheets("CaseSelect").Range("A1") = "GP3BR1SA" Then
Call GP3BR1S
ElseIf Sheets("CaseSelect").Range("A1") = "GP1BR2S2B" Then
Call GP1BR2S2B
ElseIf Sheets("CaseSelect").Range("A1") = "GP1BR2S1I" Then
Call GP1BR2S1I
ElseIf Sheets("CaseSelect").Range("A1") = "GP1BR2S2I" Then
Call GP1BR2S2I
ElseIf Sheets("CaseSelect").Range("A1") = "GP2BR2S2B" Then
Call GP2BR2S2B
ElseIf Sheets("CaseSelect").Range("A1") = "GP2BR2S1I" Then
Call GP2BR2S1I
ElseIf Sheets("CaseSelect").Range("A1") = "GP2BR2S2I" Then
Call GP2BR2S2I
ElseIf Sheets("CaseSelect").Range("A1") = "GP3BR2S2B" Then
Call GP3BR2S2B
ElseIf Sheets("CaseSelect").Range("A1") = "GP3BR2S1I" Then
Call GP3BR2S1I
ElseIf Sheets("CaseSelect").Range("A1") = "GP3BR2S2I" Then
Call GP3BR2S2I
Else
' Do nothing
End If
End Sub
When I change one of the inputs I get "Run-Time error '-2147417848 (80010108)': Method 'Range' of object '_Worksheet' failed"
When I debug this it highlights my second line of code, "If Sheets("CaseSelect").Range("$A$1").Value = "GP1BR1S" Then" as being the problem.
An interesting point to note is that it seems as though the Macro GP1BR1S is being called as some of the formatting is being changed, something that the Macro is supposed to do. However none of the other functions of the Macro are being ran.
All of the Macros do essentially the same thing, which is to clear the existing contents of certain cells, and then to replace the contents of those cells with the contents of another worksheet.
Below is an example of one of the Macros (GP1BR1S);
Code:
Sub GP1BR1S()
'
' GP1BR1S Macro
'
'
Application.ScreenUpdating = False
Call UnprotectAll
ActiveSheet.DrawingObjects.Select
Selection.Delete
Sheets("Report").Range("W20:AL46").Select
Selection.Clear
Sheets("GP1BR1S").Range("W20:AL46").Copy Destination:=Sheets("Report").Range("W20")
Sheets("GP1BR1S").Range("W61:AL87").Copy Destination:=Sheets("Report").Range("W61")
Sheets("GP1BR1S").Range("U105:AN142").Copy Destination:=Sheets("Report").Range("U105")
Sheets("GP1BR1S").Range("$AJ$13:$AL$13").Copy Destination:=Sheets("Report").Range("$AJ$17:$AL$17")
Sheets("GP1BR1S").Range("$AJ$14:$AL$14").Copy Destination:=Sheets("Report").Range("$AJ$18:$AL$18")
' Tab Plate End Distance
Range("Z17:AB17").Select
ActiveCell.FormulaR1C1 = "=Report!R[8]C[4]"
Range("Z18:AB18").Select
' Gusset Plate/Tab Plate Width
Range("AJ18:AL18").Select
ActiveCell.FormulaR1C1 = "=Report!R[14]C"
Range("AJ19").Select
' Gusset Plate Length Value
Range("Z18:AB18").Select
ActiveCell.FormulaR1C1 = "=R[-2]C+R[-1]C+R[-1]C[10]+5-R[2]C[-21]-5"
Range("Z19").Select
Worksheets("SHS 1 - 2").Shapes("Picture 2").Copy
Worksheets("Report").Paste Range("G24")
Worksheets("SHS 1 - 2").Shapes("Picture 8").Copy
Worksheets("Report").Paste Range("G37")
Sheets("SHS 1 - 2").Range("A105:T142").Copy Destination:=Sheets("Report").Range("A105")
Call ProtectAll
Application.ScreenUpdating = True
End Sub
Thanks in advanced for any help you can give me. If you need me to give you more information about the code or the worksheets then just let me know. Also I'm fairly new to using VBA and would appreciate it if you could explain any answers you can provide, just to help me learn and understand.
Kind regards,
Connor