open a file based on VLookUp result

Flavien

Board Regular
Joined
Jan 8, 2023
Messages
78
Office Version
  1. 365
Platform
  1. Windows
Hello everybody,

I have created a workbook that serves as both a database and to create cards that are printed. Each row / card has a unique ID number of type YY-MM-1234.
Since sometimes there are errors when writing the cards, I would like to be able to modify the desired row and update the workbook corresponding to the card.
For your information, The ID's line you want to modify is entered in a cell ("Ext" in the code) and then a sheet "CS" (in the code) is displayed with the line to be corrected. To finish the modified row is transferred to the "Card" workbook and then to the database.

The link to the record is in my database. I think it's a good idea to retrieve this link with a VlookUp function in order to open the desired workbook.

I can open the workbook I want here called "VLKUP1" (in the code), but I can't set it to be able to transfer my data. Also, I don't know how to replace the old database row with the corrected one in the database to avoid duplication.

Does anyone have an idea please?

Thank you in advance.



VBA Code:
Sub Collecte()

'Boucle sur tous les classeurs FNC ilot et transfère les données vers ce classeur.
'Les lignes collectées sont datées dans les fichiers sources afin d'éviter les doublons

Dim BDD As FileDialog 'déclare la variable BDD (Boîte de Dialogue Dossier)
Dim CA As String 'déclare la variable CA (Chemin d'Accès)
Dim CD As Workbook 'déclare la variable CD (Classeur Destination)
Dim OD As Worksheet 'déclare la variable OD (Onglet Destination)
Dim FS As String 'décalre la variable FS (Fichier Source)
Dim CS As Workbook 'déclare la variable CS (Classeur Source)
Dim OS As Worksheet 'déclare la variable OS (Onglet Source)
Dim DEST As Range 'déclare la variable DEST (celllue de DESTination)
Dim Ext, Ext2 As Variant


'Désactive la mise à jour de l'écran pour accélérer l'exécution
    Application.ScreenUpdating = False

'chemin d'accès au dossier de stockage des classeurs de FNC qu'on souhaite mettre à jour
    CA = "P:\04-Production Besancon\Qualité\02 - Fiches des Produits Non Conformes\ESSAIS" & "\"

'   FNC Recherchée
    Ext = ThisWorkbook.Worksheets("Accueil").Range("Concat_Num_FNC").Value


'   ouvrir le classeur selon lien écrit dans Tableau FNC
    VLKUP1 = WorksheetFunction.VLookup(Ext, Worksheets("Tableau FNC").Range("Tableau_FNC"), 59, False) 'lien classeur FNC pour pièce jointe
    Workbooks.Open Filename:=VLKUP1

'   Définir VLKUP1
    Ext2 = VLKUP1.Value

    Set CD = Workbooks(Ext2) 'définit la classeur destination CD
    Set OD = CD.Sheets("Cartouche") 'définit l'onglet destination OD

    Set CS = ActiveWorkbook 'définit la classeur source CS
    Set OS = CS.Worksheets("Modification") 'définit l'onglet source OS (à adapter à ton cas, ici j'ai mis le premier onglet)


'   Copier les données modifiées vers le classeur FNC à modifier
    CS.OS.Range("A4:Q4").Copy: CD.OD.Range("A3:Q3").PasteSpecial Paste:=xlPasteValues



End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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