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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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
 
Upvote 0
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!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,378
Messages
6,119,188
Members
448,873
Latest member
jacksonashleigh99

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