Hi Everyone,
I am trying to add a simple property to the macro. If someone pastes information, there is a run-time 9 error. I want to have an "If Error" statement that alerts the user, and tells them to press ctrl+z to undo, then the procedure works fine.
However, the If Error statement is causing me problems. When I run it, I get a Runtime 5: Invalid procedure, call or argument. I have highlighted the line with the bug.
Any help would be much appreciated!
Thanks a lot!
I am trying to add a simple property to the macro. If someone pastes information, there is a run-time 9 error. I want to have an "If Error" statement that alerts the user, and tells them to press ctrl+z to undo, then the procedure works fine.
However, the If Error statement is causing me problems. When I run it, I get a Runtime 5: Invalid procedure, call or argument. I have highlighted the line with the bug.
Any help would be much appreciated!
Thanks a lot!
Code:
Sub getResults()
ActiveSheet.Unprotect Password:="Syncos123!"
Sheets("selector").Activate
Dim resultDrop As Range
Set resultDrop = Sheets("Selector").Range("A12")
Dim outcomeDrop As Range
Set outcomeDrop = Sheets("Selector").Range("A24")
Dim dOutcomeSelect As String
dOutcomeSelect = Sheets("Selector").Range("A8").Value
'Sheets("Master List").Activate
Dim dOutcomeList As Range
Set dOutcomeList = Sheets("Master List").Range("C2:BD4")
Dim masterRange As Range
Set masterRange = Sheets("Master List").Range("C2:BD28")
Dim dOutcomePos As Range
Set dOutcomePos = masterRange.Find(dOutcomeSelect)
Dim resultQuant As Long
[COLOR=#b22222]If Error Then MsgBox "You cannot paste information. Press ctrl+Z to undo, and then select from the drop"[/COLOR]
resultQuant = dOutcomePos.Offset(2, 0).Value
Dim outcomeQuant As Long
outcomeQuant = dOutcomePos.Offset(2, 1).Value
Dim resultRange As Range
Set resultRange = Range(dOutcomePos.Offset(3, 0), dOutcomePos.Offset(resultQuant + 2, 0))
Dim outcomeRange As Range
Set outcomeRange = Range(dOutcomePos.Offset(3, 1), dOutcomePos.Offset(outcomeQuant + 2, 1))
ActiveWorkbook.Names.Add Name:="ValListR", RefersTo:=resultRange
ActiveWorkbook.Names.Add Name:="ValListO", RefersTo:=outcomeRange
With resultDrop.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=ValListR"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
With outcomeDrop.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=ValListO"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
resultDrop.Value = resultRange(1, 1).Value
outcomeDrop.Value = outcomeRange(1, 1).Value
MsgBox "The 'Results' and 'Outcomes' have been updated based on your selection of the 'Desired Outcome'. Please select the applicable Result and Outcome from the drop-down menu and copy it to the clipboard using the button before pasting it into GAIMS"
ActiveSheet.Protect Password:="Syncos123!", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub