file name that contains a string VS an exact match

kmahraz

New Member
Joined
Sep 10, 2015
Messages
42
Hello
Code below work perfectly for the exact match, would like some assistance to change it so that it finds any document that contains a string
Code:
[COLOR=#E56717][FONT=Consolas][B]ub[/B][/FONT][/COLOR][COLOR=#141414][FONT=Consolas] Run()[/FONT][/COLOR]
[COLOR=#151B8D][FONT=Consolas][B]Dim[/B][/FONT][/COLOR][COLOR=#141414][FONT=Consolas] LRow [/FONT][/COLOR][COLOR=#151B8D][FONT=Consolas][B]As[/B][/FONT][/COLOR][COLOR=#F660AB][FONT=Consolas][B]Integer[/B][/FONT][/COLOR]
[COLOR=#151B8D][FONT=Consolas][B]Dim[/B][/FONT][/COLOR][COLOR=#141414][FONT=Consolas] LPath [/FONT][/COLOR][COLOR=#151B8D][FONT=Consolas][B]As[/B][/FONT][/COLOR][COLOR=#F660AB][FONT=Consolas][B]String[/B][/FONT][/COLOR]
[COLOR=#151B8D][FONT=Consolas][B]Dim[/B][/FONT][/COLOR][COLOR=#141414][FONT=Consolas] LExtension [/FONT][/COLOR][COLOR=#151B8D][FONT=Consolas][B]As[/B][/FONT][/COLOR][COLOR=#F660AB][FONT=Consolas][B]String[/B][/FONT][/COLOR]
[COLOR=#151B8D][FONT=Consolas][B]Dim[/B][/FONT][/COLOR][COLOR=#141414][FONT=Consolas] LContinue [/FONT][/COLOR][COLOR=#151B8D][FONT=Consolas][B]As[/B][/FONT][/COLOR][COLOR=#F660AB][FONT=Consolas][B]Boolean[/B][/FONT][/COLOR]
[COLOR=#008000][FONT=Consolas]'Initialize variables
[/FONT][/COLOR][COLOR=#141414][FONT=Consolas]  LContinue = [/FONT][/COLOR][COLOR=#00C2FF][FONT=Consolas][B]True[/B][/FONT][/COLOR]
[COLOR=#141414][FONT=Consolas]   LRow = 2[/FONT][/COLOR]
[COLOR=#141414][FONT=Consolas]   LPath = [/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"C:\Users\Sophia\Downloads\New folder\"[/FONT][/COLOR]
[COLOR=#141414][FONT=Consolas]   LExtension = [/FONT][/COLOR][COLOR=#800000][FONT=Consolas]".xl*"[/FONT][/COLOR]
[COLOR=#008000][FONT=Consolas]'Loop through all column A values until a blank cell is found
[/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]While[/B][/FONT][/COLOR][COLOR=#141414][FONT=Consolas] LContinue[/FONT][/COLOR]
[COLOR=#008000][FONT=Consolas]'Found a blank cell, do not continue
[/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]If[/B][/FONT][/COLOR][COLOR=#141414][FONT=Consolas] Len(Range([/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"A"[/FONT][/COLOR][COLOR=#141414][FONT=Consolas] & CStr(LRow)).Value) = 0 [/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]Then[/B][/FONT][/COLOR]
[COLOR=#141414][FONT=Consolas]         LContinue = [/FONT][/COLOR][COLOR=#00C2FF][FONT=Consolas][B]False[/B][/FONT][/COLOR]
[COLOR=#008000][FONT=Consolas]'Check if file exists for part number
[/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]Else[/B][/FONT][/COLOR]
[COLOR=#008000][FONT=Consolas]'Place "No" in column B if the file does NOT exist
[/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]If[/B][/FONT][/COLOR][COLOR=#141414][FONT=Consolas] Len(Dir(LPath & Range([/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"A"[/FONT][/COLOR][COLOR=#141414][FONT=Consolas] & CStr(LRow)).Value & LExtension)) = 0 [/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]Then[/B][/FONT][/COLOR]
[COLOR=#141414][FONT=Consolas]            Range([/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"B"[/FONT][/COLOR][COLOR=#141414][FONT=Consolas] & CStr(LRow)).Value = [/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"No"[/FONT][/COLOR]
[COLOR=#008000][FONT=Consolas]'Place "Yes" in column B if the file does exist
[/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]Else[/B][/FONT][/COLOR]
[COLOR=#141414][FONT=Consolas]            Range([/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"B"[/FONT][/COLOR][COLOR=#141414][FONT=Consolas] & CStr(LRow)).Value = [/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"Yes"[/FONT][/COLOR]
[COLOR=#8D38C9][FONT=Consolas][B]End[/B][/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]If[/B][/FONT][/COLOR]
[COLOR=#8D38C9][FONT=Consolas][B]End[/B][/FONT][/COLOR][COLOR=#8D38C9][FONT=Consolas][B]If[/B][/FONT][/COLOR]
[COLOR=#141414][FONT=Consolas]      LRow = LRow + 1[/FONT][/COLOR]
[COLOR=#141414][FONT=Consolas]   Wend[/FONT][/COLOR]
[COLOR=#8D38C9][FONT=Consolas][B]End[/B][/FONT][/COLOR][COLOR=#E56717][FONT=Consolas][B]Sub[/B][/FONT][/COLOR]

Thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Code:
If Len(Dir(LPath [COLOR="#FF0000"]& "*" &[/COLOR]  Range("A" & CStr(LRow)).Value [COLOR="#FF0000"]& "*" &[/COLOR] LExtension)) = 0 Then
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,851
Members
449,051
Latest member
excelquestion515

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