File path code update needed

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello I need help:


Code:
Dim sfile$, fpath$
With Application
    Fpath = ThisWorkbook.Path  & .pathSeparator & “Pictures” & .pathSeparator 
    sFile = Dir(fPath & .PathSeparator & TextBox1.Text & “.*”)
Image1.Picture  = LoadPicture(“”)
If sFile<>”” Then Image1.Picture = LoadPicture(fPath & .pathSeparator & sFile)
End With


I am looking for a way to make sure that when I have say


“Kelly mort” in the textbox and “mort kelly” in the image folder , I want it pick that file and show it in the control.


For example if I have name “A B C” Then “B C A”, “A C B”, “C A B”, etc are all valid.


I just got stacked.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Kelly,
You might be able to accomplish this by splitting your search string into separate strings and using instr() to find matches. This would require checking every file in the directory for matches to each search term. Something like this maybe:

str_search1 = "Kelly"
str_search2 = "Mort"

'Grab your next file name here
str_fileName = "Mort Kelly.xxx"

if instr(1, str_fileName, str_search1, vbTextCompare) > 0 then
if instr(1, str_fileName, str_search2, vbTextCompare) > 0 then
'Found a file name that has both terms
End If
End If
 
Upvote 0
Okay cool.

But the is that there may be variable number of names .

And I don't also understand this approach that much.

Can you make it a bit clearer for me?
 
Upvote 0
This was just a simple mockup not a full solution. The idea here is that you can get the name you are looking for in a string and split it into multiple search terms. Then you can search each of those terms individually. The instr() function searches for a search term anywhere in the string. If the first term is found, then we search for the second term. If they both are found, then you have a match.
 
Upvote 0
This was just a simple mockup not a full solution. The idea here is that you can get the name you are looking for in a string and split it into multiple search terms. Then you can search each of those terms individually. The instr() function searches for a search term anywhere in the string. If the first term is found, then we search for the second term. If they both are found, then you have a match.


Okay cool.

Then let's do this.

I am ready for any solution that works.
 
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