File path code update needed

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,734
Office Version
2016
Platform
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.
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

BlueAure

New Member
Joined
May 21, 2019
Messages
46
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
 

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,734
Office Version
2016
Platform
Windows
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?
 

BlueAure

New Member
Joined
May 21, 2019
Messages
46
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.
 

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
1,734
Office Version
2016
Platform
Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,096,459
Messages
5,450,577
Members
405,619
Latest member
mjh237

This Week's Hot Topics

Top