Hello, I made a code that allows me to forward a line to an email.
The code works great if the desired line is saved on one of the two tabs.
If the line I'm looking for doesn't exist at all, the first search works fine and displays a message to let me know that the program is going to look for the info in the second tab, but at that point, the code shows error 1004 on the line VLKUP_1 ignoring the line "On error GoTo InvalidVLKUP_2:
Does anyone know how to fix this?
The code works great if the desired line is saved on one of the two tabs.
If the line I'm looking for doesn't exist at all, the first search works fine and displays a message to let me know that the program is going to look for the info in the second tab, but at that point, the code shows error 1004 on the line VLKUP_1 ignoring the line "On error GoTo InvalidVLKUP_2:
Does anyone know how to fix this?
VBA Code:
Sub Acces_onglet_Modification_MAJ_FNC_EXTRAITE()
Dim email As Variant
Dim chemin As String, pos&
Dim Msg_VLKUP, Msg_PopUp As String 'variable pour MsgBox
Dim Ext, VLKUP1, VLKUP2, VLKUP3, VLKUP4, VLKUP5, VLKUP6 As Variant
Dim varMsgBoxResutlt
Dim Msg, Style, Title, Response, MyString
Dim Doc_joint As Object
Dim xRg, xRgEach As Range
Dim xAddress, xRgVal As String
Dim xRgNum, xNum As Long
Dim Lig, I As Long
Dim WS1, WS2 As Worksheet
Set WS2 = Worksheets("SUIVI")
Set WS3 = Worksheets("Modification")
' MAJ de l'écran
Application.ScreenUpdating = False
' appeler une FNC
Ext = ThisWorkbook.Worksheets("Accueil").Range("Concat_Num_FNC").Value
' Récupérer le nom du classeur
chemin = ActiveWorkbook.Name
pos = InStr(chemin, ".xlsm")
' Afficher la feuille "Modification"
Workbooks(chemin).Worksheets("Modification").Visible = True
' Masquer le rectangle "Modifier"
Workbooks(chemin).Worksheets("Modification").Shapes.Range(Array("Rectangle 1")).Visible = False
' Afficher le rectangle "Test"
Workbooks(chemin).Worksheets("Modification").Shapes.Range(Array("Rectangle 4")).Visible = True
' Tester si le numéro de fiche existe sinon message d'erreur
On Error GoTo InvalidVLKUP:
VLKUP1 = WorksheetFunction.VLookup(Ext, Worksheets("Tableau FNC").Range("Tableau_FNC"), 1, False) 'affiche numéro de FNC
Workbooks(chemin).Worksheets("Modification").Range("FNC_Num_B") = VLKUP1
GoTo VLKUPOK:
InvalidVLKUP:
Msg_1 = "La FNC que vous recherchez ne figure pas dans l'onglet Tableau FNC" & vbNewLine '& vbNewLine
Msg_1 = Msg_1 & "Nous allons la rechercher dans l'onglet SUIVI" & vbNewLine '& vbNewLine
MsgBox Msg_1, vbCritical
On Error GoTo InvalidVLKUP_2:
VLKUP1_B = WorksheetFunction.VLookup(Ext, Worksheets("SUIVI").Range("Tableau_Suivi"), 1, False) 'Line of code in error if the line you are looking for does not exist on the second sheet
Workbooks(chemin).Worksheets("Modification").Range("FNC_Num_B") = VLKUP1_B
GoTo VLKUPOK_2:
InvalidVLKUP_2:
Worksheets("Modification").Range("Saisie_B").Value = "Not Found" 'Range "Infos_Ilot" contient cellules Ilot_concerné / Rédacteur / Qualiticien
For Each Cell In Worksheets("Modification").Range("Saisie_B")
If Cell.Value = "Not Found" Then
totalfound = totalfound + 1
End If
Next Cell
MsgBox "Le numéro de FNC que vous recherchez ne figure pas dans votre extraction", vbCritical
ThisWorkbook.Worksheets("Accueil").Range("Numéro").Activate
Exit Sub
VLKUPOK:
VLKUPOK_2:
Lig = 4
For I = 2 To WS2.Range("A" & Rows.Count).End(xlUp).Row
If WS2.Cells(I, 1) = Ext Then
Range(WS2.Cells(I, "A"), WS2.Cells(I, "BD")).Copy: WS3.Cells(Lig, "A").PasteSpecial Paste:=xlPasteValues
End If
Next I
Application.CutCopyMode = False
Workbooks(chemin).Worksheets("Modification").Activate
Workbooks(chemin).Worksheets("Modification").Range("Description_Défaut_B").Select
' MAJ de l'écran
Application.ScreenUpdating = True
End Sub