performing a find and auto filter in VBA

  • Thread starter Thread starter Legacy 93538
  • Start date Start date
L

Legacy 93538

Guest
Hi

I am trying to write a macro which looks in a worksheet range C1:N1 and and finds the value in cell B1 and then in that cell put an autofilter on and filter out the blanks.

Does anyone know how to do this? As i am stuck for ideas i have considered a counta but not sure that would work. i tried doing an autofilter which filters each column in the range to filter out blanks on each column.

Thank you
Jessicaseymour
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi, try:
Code:
Sub StickingPensInNasalOrrifices()
Dim SearchRange As Range, SearchItem As Range
Dim SearchValue As Variant
Dim msg As String
Dim i As Long
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
i = Range("N" & Rows.Count).End(xlUp).Row
Set SearchRange = Range("C1:N" & i)
SearchValue = Range("B1")
msg = "Item not found"
On Error Resume Next
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Set SearchItem = SearchRange.Find(what:=SearchValue, after:=Range("C1"), LookIn:=xlValues, LookAt:=xlWhole, _
    SearchOrder:=xlByColumns, SearchDirection:=xlNext)
 
If SearchItem Is Nothing Then
    MsgBox msg
    ActiveSheet.AutoFilterMode = False
Else
    SearchRange.AutoFilter field:=SearchItem.Column - 2, Criteria1:="<>"
End If
With Application
    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With
 
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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