I'm a little confused about why i'm getting an error with this code. Run-time error '1004': Method 'Intersect' of object '_Global' failed.
This code is written in the worksheet module for sheet "INPUT (2)"
If I step through each line with F8 and stop just before the failure, I can type in the immediate window
And I get the correct sheet -"test"- so I know that bit of code is working proper.
And if I then type
I get the wrong sheet -"INPUT (2)"-but I dont understand why.
If I'm using
to set sheet "test" as the activesheet, shouldnt any ranges without a sheet specified refer to the active sheet?
I've found the code below works, but I dont understand why I have to specify activesheet with that range, after setting the active sheet explicitly?
This code is written in the worksheet module for sheet "INPUT (2)"
Code:
Sub Worksheet_Change(ByVal Target As Range)
'''''''''''''''''''''''''
Dim 'delcarations'<ALL declarations my declarations<ALL><ALL here up declarations my> as <CORRECT types types<APPORPRIATE>'proper type'
'''''''''''''''''''''''''
Application.EnableEvents = False
'''''''''''''''''''''''''
strInBk = ThisWorkbook.Name
strOutBk = ThisWorkbook.Name
strInSht = "INPUT (2)"
strOutSht = "test"
lngStart = Workbooks(strOutBk).Sheets(strOutSht).Range("A:A").Find(What:="ITEM", LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Row
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set EValuator = New ClaEvaluator
If Target.Address = "$H$2" Then
strCase1 = "unitChange"
ElseIf Selection.Rows.Count = 1 And Selection.Columns.Count = 1 Then
strCase1 = "singleCell"
ElseIf Target.Address = Target.EntireRow.Address Then
strCase1 = "wholeRow"
ElseIf Target.Address = Target.EntireColumn.Address Then
strCase1 = "wholeCol"
ElseIf Selection.Rows.Count > 1 Or Selection.Columns.Count > 1 Then
strCase1 = "multiCell"
End If
'''''''''''''''''''''''''
Select Case strCase1
'''''''''''''''''''''''''
Case "unitChange"
With EValuator
.Range = Intersect(funTrueUsedRange, Range("3:65536"))
.Multi = True
End With
Workbooks(strOutBk).Sheets(strOutSht).Activate
FAIL---> Set rngClear = Intersect(funTrueUsedRange, Range(lngStart + 1 & ":65536"))
rngClear.Clear
'''''''''''''''''''''''''
''next case
Code:
?funTrueUsedRange.Parent.Name
And if I then type
Code:
?Range(lngStart + 1 & ":65536").Parent.Name
If I'm using
Code:
Workbooks(strOutBk).Sheets(strOutSht).Activate
I've found the code below works, but I dont understand why I have to specify activesheet with that range, after setting the active sheet explicitly?
Code:
Case "unitChange"
With EValuator
.Range = Intersect(funTrueUsedRange, Range("3:65536"))
.Multi = True
End With
Workbooks(strOutBk).Sheets(strOutSht).Activate
Set rngClear = Intersect(funTrueUsedRange, ActiveSheet.Range(lngStart + 1 & ":65536"))
rngClear.Clear
Last edited: