Ashhu
Active Member
Hello friends
Need help here,
I am trying to copy Document from specific folder. Doc name will have Part Number, Serial Number. I am trying to copy with combination part number and SL.
Column A will have part number and B with Serial Number. When I loop, its copying all files with part number match and then copying Serial number. But what i need is to copy only the Document which contains both part number and SL.
For Ex: Folder contains Doc with below names
Doc number sample:
90001234_Dec 05
90009568_Sep 05, Dec 05, Oct 03
90009568_Sep 05, Jul 15, Jan 23
When i search for 90009568 (Col A) and Dec 05 (col B)- I should get only one doc "90009568_Sep 05, Dec 05, Oct 03" where as i am getting all three. because all three will have search criteria.
Below is part of code which does this search, what its doing is searching A2 criteria and executing copy, then B2. what is should do is A2:B2 combination together it should search.
round about: what we are doing now is we are putting part number * SL to get right file, but our input will be always in separate column and we concatenate first with * at center and put that as search criteria.
Please Help
Need help here,
I am trying to copy Document from specific folder. Doc name will have Part Number, Serial Number. I am trying to copy with combination part number and SL.
Column A will have part number and B with Serial Number. When I loop, its copying all files with part number match and then copying Serial number. But what i need is to copy only the Document which contains both part number and SL.
For Ex: Folder contains Doc with below names
Doc number sample:
90001234_Dec 05
90009568_Sep 05, Dec 05, Oct 03
90009568_Sep 05, Jul 15, Jan 23
When i search for 90009568 (Col A) and Dec 05 (col B)- I should get only one doc "90009568_Sep 05, Dec 05, Oct 03" where as i am getting all three. because all three will have search criteria.
Below is part of code which does this search, what its doing is searching A2 criteria and executing copy, then B2. what is should do is A2:B2 combination together it should search.
Code:
Sub CopyFiles_Containing()
Dim sSrcFolder As String, sTgtFolder As String, sFilename As String
Dim c As Range, rPatterns As Range
Dim bBad As Boolean
Dim File_Name As String
sSrcFolder = "D:\"
sTgtFolder = "D:\Users\Desktop\New folder\"
Set rPatterns = ActiveSheet.Range("A2:B500").SpecialCells(xlConstants)
For Each c In rPatterns
sFilename = Dir(sSrcFolder & "*" & c.Text & "*")
If sFilename = "" Then
c.Interior.ColorIndex = 3
bBad = True
Else
While sFilename <> ""
FileCopy sSrcFolder & sFilename, sTgtFolder & sFilename
sFilename = Dir()
Wend
End If
Next c
End Sub
round about: what we are doing now is we are putting part number * SL to get right file, but our input will be always in separate column and we concatenate first with * at center and put that as search criteria.
Please Help
Last edited: