Searching For a value in a range and write a texte if the value is found

youbitto

New Member
Joined
Jun 8, 2022
Messages
34
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Hello!

I have multiple Sheets This Ref contains "G"

the first one where I convert to PDF for each reference

Test.xlsx
ABCDEFGHI
1
2
3
4
5
6
7
8
9
10
11
12
13Ref : 017118200320272Comment
14
15
16
17
18
19
20
Branchement


The second sheet is where I take the information from

Test.xlsx
A
2
3
4Ref
5017051500050157
6017051502408156
7017051503018136
8017051503066167
9017051503080117
10017051503096100
11017059651030139
12017118200320272
13
14
TB



The Third one is where the values to search

Test.xlsx
AB
1Reftype
2017051500050157E
3017051502250195E
4017051502408156E
5017051503018136E
6017051503066167E
7017051503080117E
8017051503096100E
9017059651030139E
10017059651030139G
11017118200320272E
12017118200320272G
Contrat


And this is the Code I use to create PDF for each Refrence

VBA Code:
Sub Brt()

Dim Ref As Range

Application.ScreenUpdating = False

lastrow = Sheets("TB").Cells(Rows.Count, "A").End(xlUp).Row

    Dim rngSrc As Range
    Dim arrRef As Variant

Set rngSrc = Sheets("TB").Range("A5:A" & lastrow)
        arrRef = rngSrc.Value2

For i = 5 To lastrow

Sheets("Branchement").Range("C12:D12").ClearContents                                'Vider les cellules
Sheets("Branchement").Range("G12:G13").ClearContents

    
    Sheets("TB").Cells(i, 1).Copy                                 'Réference
    Sheets("Branchement").Range("C13").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    
    Sheets("Branchement").Cells(13, 3).NumberFormat = "@"         'Format texte de cellele C13

    Application.CutCopyMode = False

'________________PDF

Dim wsA As Worksheet
Dim wbA As Workbook
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant

Set wbA = ActiveWorkbook
Set wsA = Sheets("Branchement")
'
strPath = wbA.Path
If strPath = "" Then
  strPath = Application.DefaultFilePath
End If

strPath = strPath & "\"

strName = wsA.Range("C13").Value _

'create default name for savng file
strFile = strName & " Fiche branchement" & ".pdf"
strPathFile = strPath & strFile

   'export to PDF in current folder
    wsA.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=strPathFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
      
    Next i

Application.ScreenUpdating = True



End Sub



My Request is that some refrences are doubled and contains "E" and "G" as you can see in "Contrat" sheet
I want while creating a PDF that if any refrence that contains "G" the value of the cell G13 in sheet "PDF" will be "This refrence Contains G"
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,886
Messages
6,175,198
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