search for a folder name in file path

PeterRichter

New Member
Joined
Oct 30, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi fellas, I have file/folder path as showing in column A. I have list of folder names in column C, I like to check if the folder name exist in column C and display the found folder name in column B, can anyone help me to solve this problem? thank you in advance

1604222464380.png
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi PeterRichter and Welcome to the Board! Do U want a spreadsheet or a VBA solution? Dave
 
Upvote 0
I came up with a UDF that seems to work. HTH. Dave
module code...
Code:
Option Explicit
Public Function FileName(ShtName As String, SearchCol As String, _
                             SearchAddress As String) As String
'B1 formula =FileName("sheet1","C","A1")
Dim Cnt As Integer, C As Range, TempArr As Variant
Application.Volatile
TempArr = Split(Sheets(ShtName).Range(SearchAddress), "\")
For Cnt = LBound(TempArr) To UBound(TempArr)
Set C = Sheets(ShtName).Range(SearchCol & ":" & SearchCol).Find _
       (What:=TempArr(Cnt), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
If Not C Is Nothing Then
FileName = Sheets(ShtName).Range(SearchCol & C.Row)
Exit Function
End If
Next Cnt
FileName = "NotMatch"
End Function
To operate for sheet1 with file address in "A & row" and keywords in "C" place this formula in "B" & row...
Code:
=FileName("sheet1","C","A2")
ie. this formula would go in B2
ps. I'm guessing there's a nifty spreadsheet formula that I won't be able to understand :)
 
Upvote 0
I came up with a UDF that seems to work. HTH. Dave
module code...
Code:
Option Explicit
Public Function FileName(ShtName As String, SearchCol As String, _
                             SearchAddress As String) As String
'B1 formula =FileName("sheet1","C","A1")
Dim Cnt As Integer, C As Range, TempArr As Variant
Application.Volatile
TempArr = Split(Sheets(ShtName).Range(SearchAddress), "\")
For Cnt = LBound(TempArr) To UBound(TempArr)
Set C = Sheets(ShtName).Range(SearchCol & ":" & SearchCol).Find _
       (What:=TempArr(Cnt), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
If Not C Is Nothing Then
FileName = Sheets(ShtName).Range(SearchCol & C.Row)
Exit Function
End If
Next Cnt
FileName = "NotMatch"
End Function
To operate for sheet1 with file address in "A & row" and keywords in "C" place this formula in "B" & row...
Code:
=FileName("sheet1","C","A2")
ie. this formula would go in B2
ps. I'm guessing there's a nifty spreadsheet formula that I won't be able to understand :)
thanks so much Dave, I will definitely try the the provided code. Only if you have a min, how would I do this without VBA?
 
Upvote 0
Whoops! That's not so good. This will let U copy down...
Code:
Option Explicit
Public Function FileName(ShtName As String, SearchCol As String, _
                             SearchAddress As String) As String
'B2 formula =FileName("sheet1","C",A2)
Dim Cnt As Integer, C As Range, TempArr As Variant
Application.Volatile
TempArr = Split(SearchAddress, "\")
For Cnt = LBound(TempArr) To UBound(TempArr)
Set C = Sheets(ShtName).Range(SearchCol & ":" & SearchCol).Find _
       (What:=TempArr(Cnt), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
If Not C Is Nothing Then
FileName = Sheets(ShtName).Range(SearchCol & C.Row)
Exit Function
End If
Next Cnt
FileName = "NotMatch"
End Function
So "B2" would be this formula...
Code:
=FileName("sheet1","C",A2)
which U can copy down. As for a non-VBa solution, we will have to wait for someone more learned than me. HTH. Dave
 
Upvote 0
Whoops! That's not so good. This will let U copy down...
Code:
Option Explicit
Public Function FileName(ShtName As String, SearchCol As String, _
                             SearchAddress As String) As String
'B2 formula =FileName("sheet1","C",A2)
Dim Cnt As Integer, C As Range, TempArr As Variant
Application.Volatile
TempArr = Split(SearchAddress, "\")
For Cnt = LBound(TempArr) To UBound(TempArr)
Set C = Sheets(ShtName).Range(SearchCol & ":" & SearchCol).Find _
       (What:=TempArr(Cnt), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
If Not C Is Nothing Then
FileName = Sheets(ShtName).Range(SearchCol & C.Row)
Exit Function
End If
Next Cnt
FileName = "NotMatch"
End Function
So "B2" would be this formula...
Code:
=FileName("sheet1","C",A2)
which U can copy down. As for a non-VBa solution, we will have to wait for someone more learned than me. HTH. Dave
This one works(y), thanks buddy
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,756
Members
448,990
Latest member
Buzzlightyear

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