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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
What would you like this function to return or do that is different to your code?
 
Upvote 0
What would you like this function to return or do that is different to your code?
I want to automatically filter another column in another sheet by entering a value in one cell without running the macro.
 
Upvote 0
I want to automatically filter another column in another sheet by entering a value in one cell without running the macro.
If you want to filter a range automatically without running a macro then you can use the FILTER function that will automatically chnge the rows filtered when the
value in cell C2 changes.

' For example:

=FILTER(B5:G13,C5:C13=Sheet8!C2,"")
 
Upvote 0
If you want to filter a range automatically without running a macro then you can use the FILTER function that will automatically chnge the rows filtered when the
value in cell C2 changes.

' For example:

=FILTER(B5:G13,C5:C13=Sheet8!C2,"")
C5:C13 has the following formula:

=IFERROR(MID(N2,1,4)*1,"")

How can I apply the filter for the above formula?
 
Upvote 0
So why are you using the MID function on N2? Why not just refer to N2 in the range C5:C13.
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.
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,290
Members
449,218
Latest member
Excel Master

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