Morning folks.
I've got a curious one that has been doing my box in for a few hours now.
I have some code in an engineering spreadsheet that selects element types from a combobox, and uses the result of that to update the Validation range in another combobox to allow selection of a particular size of element. This - thankfully - is working absolutely perfectly. See below for the original:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rngType As Range, rngSection As Range
' check which element (chord, cross-beam or bracing) has been changed (and is thus the Target for the Worksheet_Change evenet)
If Target.Address = Range("mrgChordSectionType").Address Then
Set rngType = Range("mrgChordSectionType")
Set rngSection = Range("mrgChordSectionSize")
ElseIf Target.Address = Range("mrgCrossBeamSectionType").Address Then
Set rngType = Range("mrgCrossBeamSectionType")
Set rngSection = Range("mrgCrossBeamSectionSize")
ElseIf Target.Address = Range("mrgBracingSectionType").Address Then
Set rngType = Range("mrgBracingSectionType")
Set rngSection = Range("mrgBracingSectionSize")
Else
Exit Sub
End If
' clear any previously saved or selected values for section size if the section type is changed
rngSection.Value = ""
... REST OF THE CODE GOES HERE ...
What isn't working for some ungodly reason is the following code, which is merely a cut-down version of the first, with the initial 'IF' statement removed, as there is only the one combobox set to select from:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rngType As Range, rngSection As Range
Set rngType = Range("mrgChordSectionType")
Set rngSection = Range("mrgChordSectionSize")
' clear any previously saved or selected values for section size if the section type is changed
Range("mrgChordSectionSize").Value = ""
... REST OF THE CODE GOES HERE ...
The error appears to be in the Range("mrgChordSectionSize").Value = "", which throws up the "Method 'Value' of object 'Range' has failed" error causing Excel to totally crap out.
Literally all i've done to get from the original (working) file to the new (crashing) file is do a 'Save As...' and delete the 'IF' statement for simplicity, and all hell has broken loose.
Anyone got any ideas what I might be able to try?
Bookmarks