Compile Error: Object Required when using "If" in code

hart0208

New Member
Joined
May 27, 2015
Messages
12
Hi All,

I know im getting closer, but not close enough obviously!

I have written the code below, but have been getting a Compile Error: Object Required. Are you able to help me out in fixing it?

Basically, I want the code to change the column that is auto filtered depending on a specific customer (Need column 7 filtered) in a cell on another worksheet. That specific customer is one of 4 different customer that will be entered in that cell (all other customers need column 6 filtered).


Code:
    Dim celltxt As String
    
    Set wsLiab = ActiveWorkbook.Sheets("Liability report")
    Set wsDataInput = ActiveWorkbook.Sheets("Data Input")
    Set celltxt = wsDataInput.Range("B4").Text


        
        With Sheets("Liab A")
            With .Range("A1:N" & Sheets("Liab A").Range("A" & Rows.Count).End(xlUp).Row)
                If InStr(1, celltxt, "BS1") Then
                .AutoFilter Field:=7, Criteria1:="=S*", _
                            Operator:=xlAnd
                .AutoFilter Field:=10, Criteria1:="<>0", _
                            Operator:=xlAnd
                Else
                .AutoFilter Field:=6, Criteria1:="=S*", _
                            Operator:=xlAnd
                .AutoFilter Field:=10, Criteria1:="<>0", _
                            Operator:=xlAnd
                End If
                
            End With
            .Range("A1:B" & .Range("A" & Rows.Count).End(xlUp).Row).Offset(1).SpecialCells(xlCellTypeVisible).Copy
            Sheets("Liability report").Range("A21").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                                                                                                          :=False, Transpose:=False
        End With
        Application.CutCopyMode = False
        wsLiab.Select
                Lastrow = Range("A21").End(xlDown).Row
                Range("C21:W21").AutoFill Destination:=Range(Range("C21"), Range("W" & Lastrow))
        wsLiab.Calculate


End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi All,

I know im getting closer, but not close enough obviously!

I have written the code below, but have been getting a Compile Error: Object Required. Are you able to help me out in fixing it?

Basically, I want the code to change the column that is auto filtered depending on a specific customer (Need column 7 filtered) in a cell on another worksheet. That specific customer is one of 4 different customer that will be entered in that cell (all other customers need column 6 filtered).


Rich (BB code):
    Dim celltxt As String
    
    Set wsLiab = ActiveWorkbook.Sheets("Liability report")
    Set wsDataInput = ActiveWorkbook.Sheets("Data Input")
    Set celltxt = wsDataInput.Range("B4").Text

For a starter, remove the red text, Then if you get another compile error, tell what line is causing it and someone can help you out.
 
Upvote 0
I just removed the "Set" before "celltxt" and it works perfectly. I am guessing that this was the issue behind the object error?

Thank you for your help!
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,724
Members
448,294
Latest member
jmjmjmjmjmjm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top