Object Required

Mugalh01

New Member
Joined
Mar 23, 2018
Messages
15
Hi all,

It could be that I've been at this for too long and I now can't see the obvious errors. I cannot get past the "object required" error - by the autofilter line- Any help will be greatly appreciated.

Code:
[I]Sub copysubpanel_NTC()[/I]

[I]Set FPNTC = Sheets("Full Panel NTC check")[/I]
[I]Set SPNTC = Sheets("Subpanel NTC check")[/I]

[I]Dim Lrow As Long[/I]

[I]With FPNTC[/I]
[I]Lrow = .Cells(Rows.Count, 1).End(xlUp).Row[/I]

[I].Range("H2:H234").FormulaR1C1 = "=IF('Patient demographics'!R2C6=""Colorectal"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-7],0)),IF('Patient demographics'!R2C6=""Breast"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-6],0)),IF('Patient demographics'!R2C6=""GIST"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-5],0)),IF('Patient demographics'!R2C6=""Glioma"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-4],0)),IF('Patient demographics'!R2C6=""HN"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-3],0)),IF('Patient demographics'!R2C6=""Lung"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-2],0)),IF('Patient demographics'!R2C6=""Melanoma"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-1],0)),IF('Patient demographics'!R2C6=""Ovarian"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C,0)),IF('Patient demographics'!R2C6=""Prostate"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[1],0)),IF('Patient demographics'!R2C6=""Thyroid"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[2],0)),FALSE))))))))))"[/I]

[B][I]FPNTC.Cells.Selection.AutoFilter.Range("A1").AutoFilter Field:=8, Criteria1:="TRUE"[/I][/B]
[I]FPNTC.Range("A2:H" & Lrow).Select[/I]
[I]Selection.Copy[/I]
[I]SPNTC.Range("A2").PasteSpecial xlPasteValues[/I]

[I]Application.CutCopyMode = False[/I]

[I]End With[/I]
[I]
[End Code]. 

Thank you[/I]
[I]End Sub[/I]
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Thanks Dave, I've tweaked the code as suggested and it seems to be working fine - the question I've got is if I'm within the 'With' function (i.e. 'with FPNTC' as in the code below), why do i still have to state the sheet further down (i.e. 'sheets ("Full Panel NTC check")? Just so that I can better understand VBA.

Code:
[/I][I]Sub copysubpanel_NTC()[/I]

[I]Set FPNTC = Sheets("Full Panel NTC check")[/I]
[I]Set SPNTC = Sheets("Subpanel NTC check")[/I]

[I]Dim Lrow As Long[/I]

[I]With FPNTC[/I]
[I]Lrow = .Cells(Rows.Count, 1).End(xlUp).Row[/I]

[I].Range("H2:H234").FormulaR1C1 = "=IF('Patient demographics'!R2C6=""Colorectal"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-7],0)),IF('Patient demographics'!R2C6=""Breast"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-6],0)),IF('Patient demographics'!R2C6=""GIST"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-5],0)),IF('Patient demographics'!R2C6=""Glioma"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-4],0)),IF('Patient demographics'!R2C6=""HN"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-3],0)),IF('Patient demographics'!R2C6=""Lung"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-2],0)),IF('Patient demographics'!R2C6=""Melanoma"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-1],0)),IF('Patient demographics'!R2C6=""Ovarian"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C,0)),IF('Patient demographics'!R2C6=""Prostate"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[1],0)),IF('Patient demographics'!R2C6=""Thyroid"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[2],0)),FALSE))))))))))"[/I]

[I]Sheets("Full Panel NTC check").Select[/I]
[I]Cells.Select[/I]
[I]Selection.AutoFilter[/I]
[I]Range("A1").AutoFilter Field:=8, Criteria1:="TRUE"[/I]
[I]FPNTC.Range("A2:H" & Lrow).Select[/I]
[I]Selection.Copy[/I]
[I]SPNTC.Range("A2").PasteSpecial xlPasteValues[/I]

[I]Application.CutCopyMode = False[/I]

[I]End With[/I]

[I]End Sub

[End CODE][/I]
 
Upvote 0
There's no need to select anything, try
Code:
Sub copysubpanel_NTC()
   Dim FPNTC As Worksheet, SPNTC As Worksheet

   Set FPNTC = Sheets("Full Panel NTC check")
   Set SPNTC = Sheets("Subpanel NTC check")
   
   Dim Lrow As Long
   
   With FPNTC
      Lrow = .Cells(Rows.Count, 1).End(xlUp).Row
      
      .Range("H2:H" & Lrow).FormulaR1C1 = "=IF('Patient demographics'!R2C6=""Colorectal"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-7],0)),IF('Patient demographics'!R2C6=""Breast"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-6],0)),IF('Patient demographics'!R2C6=""GIST"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-5],0)),IF('Patient demographics'!R2C6=""Glioma"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-4],0)),IF('Patient demographics'!R2C6=""HN"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-3],0)),IF('Patient demographics'!R2C6=""Lung"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-2],0)),IF('Patient demographics'!R2C6=""Melanoma"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[-1],0)),IF('Patient demographics'!R2C6=""Ovarian"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C,0)),IF('Patient demographics'!R2C6=""Prostate"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[1],0)),IF('Patient demographics'!R2C6=""Thyroid"",ISNUMBER(MATCH(C[-6], 'PanCancer Panels'!C[2],0)),FALSE))))))))))"
      
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A1").AutoFilter Field:=8, Criteria1:="TRUE"
      .Range("A2:H" & Lrow).Copy
      SPNTC.Range("A2").PasteSpecial xlPasteValues
      
      Application.CutCopyMode = False
      .AutoFilterMode = False
   End With

End Sub
 
Upvote 0
Fluff I don't know what you've done here but it works beautifully!! Thank you.
I'll analyse it and use it elsewhere.
Thanks again.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,099
Members
452,379
Latest member
IainTru

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