I have 'Workbook1' which has command buttons to perform certain operations. When a button is clicked in this workbook, it downloads a different workbook from Outlook and opens that workbook with a variable name, which is 'Workbook2'. After this, I want to set a filter in that workbook. But I'm not able to do that. I am getting 'Object Variable or With Block Variable not set' error. Below is my code.
Dim EXCELApplication As Object Dim DefPath As Variant Dim wb As Workbook Dim wbName As String Dim col2 As Long Dim colNameF As Long Dim colNameF1 As Long Dim colNameF2 As Long ' Other Relevant Code Present Here' DoEvents Set EXCELApplication = CreateObject("Excel.Application") EXCELApplication.Workbooks.Open (DefPath & strExt & ".xlsb") EXCELApplication.Visible = True EXCELApplication.Sheets("Release Level View").Activate colNameF = Range("A8:DD8").Find(What:="Teams", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False).Column colNameF1 = Range("A8:DD8").Find(What:="Items", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False).Column colNameF2 = Range("A8:DD8").Find(What:="Domain", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False).Column ActiveSheet.Range("$A$8:$DD$9999").AutoFilter Field:=colNameF, Criteria1:="ST Test", Operator:=xlOr, Criteria2:="" ActiveSheet.Range("$A$8:$DD$9999").AutoFilter Field:=colNameF1, Criteria1:="Variance", Operator:=xlOr, Criteria2:="" ActiveSheet.Range("$A$8:$DD$9999").AutoFilter Field:=colNameF2, Criteria1:="9S", Operator:=xlOr, Criteria2:="" I'm getting the error in this particular line.
colNameF = Range("A8:DD8").Find(What:="Teams", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False).Column Even if i use ActiveSheet.Range.. I'm still getting the same error. Can someone tell me what the problem is?
Thanks BK201, even when I use Set, i'm still getting the same error. Here's the complete code for your understanding.
With targetSht Set aCell1 = EXCELApplication.Range("A8:DD8").Find(What:="Feb", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False) If Not aCell1 Is Nothing Then col2 = aCell1.Column SV1 = Split(Cells(col2).Address, "$")(1) lRow1 = .Range(SV1 & .Rows.Count).End(xlUp).Row End If colNameF = .Range("A8:DD8").Find(What:="Teams", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False).Column colNameF1 = .Range("A8:DD8").Find(What:="Items", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False).Column colNameF2 = .Range("A8:DD8").Find(What:="Domain", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False).Column .Range("$A$8:$DD$9999").AutoFilter Field:=colNameF, Criteria1:="ST Test", Operator:=xlOr, Criteria2:="" .Range("$A$8:$DD$9999").AutoFilter Field:=colNameF1, Criteria1:="Variance", Operator:=xlOr, Criteria2:="" .Range("$A$8:$DD$9999").AutoFilter Field:=colNameF2, Criteria1:="9S", Operator:=xlOr, Criteria2:="" .Cells(lRow1 + 1, SV1).Select Selection.NumberFormat = "0" SumV1 = SV1 & "9" SumW1 = SV1 & lRow1 .Cells(lRow1 + 1, SV1).Formula = "=SUBTOTAL(9," & SumV1 & ":" & SumW1 & ")" .Cells(lRow1 + 1, SV1).Select Selection.Copy End With Windows("DS.xlsx").Activate Set FindV = Range("A1:Z100").Find(What:="Dec Rel", LookIn:=xlValues, LookAt:=xlWhole, _ MatchCase:=False, SearchFormat:=False) FindV.Offset(0, 4).NumberFormat = "0" FindV.Offset(0, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Whereever the 'cells' method is encountered, I get the same error everywhere.
Findmatches nothing?