[UPGRADE CODE] Find and open specific file based on a reference value that the user fill in

Status
Not open for further replies.

eddorena

New Member
Joined
Dec 3, 2021
Messages
47
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have some VBA code below that functioned as lookup value based on user fill in in specific cell (bapref), and now I need to modify the code search the lookup file with a specific name on same folder based on the (bapref) and add new formulas below.

Excel Formula:
=FILTER(XLOOKUP(ISGPN,'[FILEBAPREF.xlsx]Sheet1'!$B:$B,'[FILEBAPREF.xlsx]Sheet1'!$G:$G,"",0),XLOOKUP(A:A,'[FILEBAPREF.xlsx]Sheet1'!$B:$B,'[FILEBAPREF.xlsx]Sheet1'!$G:$G,"",0)<>"")

This is the VBA Code

VBA Code:
Sub detail_sync()

Dim detaillist As Workbook
Dim bapref As Range
Dim sfdcnum As Range
Dim euname As Range
'Plan New Added
Dim isgpn As Range


With Worksheets("Deatil Info")

     Set bapref = .Range("oi_bapref")
     Set sfdcnum = .Range("oi_sfdcnum")
     Set euname = .Range("oi_euname")
     'Plan New Added
     Set isgpn = .Range ("ISGPN")
        
If bapref.Value = 0 Then

    MsgBox "CAUTION....BAP Number can't empty", , _
    "      !!!!!.....ERROR WARNING.....!!!!!"
        
Exit Sub
    
    End If
 
        End With

                On Error Resume Next
 
                    Set detaillist = Workbooks("DataInfo.xlsx")
 
                On Error GoTo 0
 
If detaillist Is Nothing Then
    
    [B]'I need modify from here by search specific file name that same with (bapref) with extension .xlsx (with same folder below)[/B]
    Set detaillist = Workbooks.Open("hhttps://workme.sharepoint.com/Shared Documents/General/08. formID/02. ID/DataInfo.xlsx")
      
        If Application.WorksheetFunction.XLookup(bapref.Value, detaillist.Worksheets("DetailInfo1").Range("D:D"), detaillist.Worksheets("DetailInfo1").Range("D:D"), "E", 0) = "E" Then
    
            detaillist.Close False
    
                MsgBox "BAP number not found" & vbNewLine & "Please check the BAP number or contact admin for update the database", , "                                        !!!!!.....ERROR WARNING.....!!!!!"
 
Exit Sub
    
        End If
    
             End If
              
                  
                On Error Resume Next
 
                    Set detaillist = Workbooks("DataInfo.xlsx")
 
                On Error GoTo 0
                  
                    If detaillist Is Nothing Then
    
                        Set detaillist = Workbooks.Open("hhttps://workme.sharepoint.com/Shared Documents/General/08. formID/02. ID/DataInfo.xlsx")
                
                    End If
            
                    [B]'Add the optional formula in here[/B]
                    sfdcnum.Value = Application.WorksheetFunction.XLookup(bapref.Value, detaillist.Worksheets("DetailInfo1").Range("D:D"), detaillist.Worksheets("DetailInfo1").Range("N:N"), """", 0)
                    euname.Value = Application.WorksheetFunction.XLookup(bapref.Value, detaillist.Worksheets("DetailInfo1").Range("D:D"), detaillist.Worksheets("DetailInfo1").Range("F:F"), """", 0)
            
                    detaillist.Close False
                

End Sub

The example of the bapref is BAP-123 then the file will open is BAP-123.xlsx then running the same lookup process (including new formula)

I really appreciate for the support 🙏
 

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.
Status
Not open for further replies.

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