VBA Filter by value

arsentievalex

New Member
Joined
Mar 18, 2020
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

Hope you could help with this piece of code. I want to filter data by value and select using Ctrl right + Ctrl down to further paste in into an email. However, something seems to be off with the below code:

count_row = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))
count_col = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlToRight)))

Set table3 = Sheets("Sheet1").Range("A1").AutoFilter Field:=2, Criteria1:= _"Grocery", Range(Sheets("Sheet1").Cells(1, 1), Sheets("Sheet1").Cells(count_row, count_col))

It says the issue with Field:=2 part but I don't know how to fix it.

Thanks in advance for your help :)
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,010
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Sub arsentievalex()
   Dim Rng As Range
   
   With Sheets("Sheet1")
      .Range("A1").AutoFilter 2, "Grocery"
      Set Rng = .AutoFilter.Range.SpecialCells(xlVisible)
      .AutoFilterMode = False
   End With
   
End Sub
 

arsentievalex

New Member
Joined
Mar 18, 2020
Messages
15
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Sub arsentievalex()
   Dim Rng As Range
  
   With Sheets("Sheet1")
      .Range("A1").AutoFilter 2, "Grocery"
      Set Rng = .AutoFilter.Range.SpecialCells(xlVisible)
      .AutoFilterMode = False
   End With
  
End Sub

Yes, it works just well. Thank you a lot!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,010
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,130,400
Messages
5,641,927
Members
417,247
Latest member
Chitaah

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
Top