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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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