How to convert this VBA code to UDF code?

shafiey

Board Regular
Joined
Sep 6, 2023
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Option Explicit
Sub FilterBasedOnCellValueAnotherSheet()
Dim category As Range
With Worksheets("Sheet8")
Set category = .Range("C2")
End With
With Worksheets("Sheet7")
With .Range("B4:G13")
.AutoFilter Field:=2, Criteria1:=category, VisibleDropDown:=True
End With
End With
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
So do you want to apply two criteria?

If C5:C13 cells all hold the same value why filter on that column?
No, All numbers are not the same, the numbers are 4 digits and different. For example, 1352, 1400, 1402, etc
 
Upvote 0
Sorry.
In N2, there is a number with a general format and a pattern similar to 1352/10/24.
When the formula is implemented on it, only its 4-digit number remains, for example 1352.
So use something like this but you will to change the D5:D13=1 to whatever column you want to filter and the criteria value.

=FILTER(B5:G13,(C5:C13=Sheet8!C2) *(D5:D13=1),"")
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,101
Members
449,205
Latest member
ralemanygarcia

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