trouver le numéro de ligne d'une variable sur vba

Karim92

XLDnaute Nouveau
Bonsoir tout le monde,

Je cherche à trouver le numéro de ligne d'une variable (qui changera au fur et à mesure du code). Cela me permettra d'exporter la ligne ou se trouve cette variable.

Voici mon code :
VB:
Sub filtreRY()

'

' filtreRY Macro

'

Sheets("Investible Universe").Activate



Dim FinalRow%, i%, l



Dim yield



Application.ScreenUpdating = False



   ' ActiveSheet.Range("$A$1:$Z$549").AutoFilter Field:=20, Criteria1:="=0,2", _

   '     Operator:=xlOr, Criteria2:="=#N/A N/A"

 

Set ytm = Rows("1:1").Find("YTM", LookAt:=xlWhole, MatchCase:=False)

    Col_YTM = ytm.Column



Set ProbDef3Y = Rows("1:1").Find("Proba de défaut 3Y", LookAt:=xlWhole, MatchCase:=False)

    Col_ProbDef3Y = ProbDef3Y.Column



Set Recovery_Yield = Rows("1:1").Find("Recovery Yield", LookAt:=xlWhole, MatchCase:=False)

    Col_Recovery_Yield = Recovery_Yield.Column



FinalRow = Cells(Rows.Count, 1).End(xlUp).Row





'on trie les valeurs sur la colonne Recevery Yield afin de faire tourner la macro et sélectionner les meilleurs YTM

ActiveWorkbook.Worksheets("Investible Universe").AutoFilter.Sort.SortFields. _

        Clear

    ActiveWorkbook.Worksheets("Investible Universe").AutoFilter.Sort.SortFields. _

        Add2 Key:=Range("T1:T549"), SortOn:=xlSortOnValues, Order:=xlAscending, _

        DataOption:=xlSortNormal

    With ActiveWorkbook.Worksheets("Investible Universe").AutoFilter.Sort

        .Header = xlYes

        .MatchCase = False

        .Orientation = xlTopToBottom

        .SortMethod = xlPinYin

        .Apply

    End With



For i = 2 To FinalRow

 

    If Cells(i, Col_Recovery_Yield).Value <= 0.2 Then

    Rows(i).Select

    Selection.Cut

    Application.CutCopyMode = False

    Selection.Delete Shift:=xlUp

    i = i - 1

    End If

 

    If Cells(i, Col_Recovery_Yield) = "#N/A N/A" Then

    Rows(i).Select

    Selection.Cut

    Application.CutCopyMode = False

    Selection.Delete Shift:=xlUp

    i = i - 1

    End If

 

Next i

 

 

For i = 2 To FinalRow



yield = Cells(i, Col_YTM)

    While Cells(i + 1, Col_ProbDef3Y) = Cells(i, Col_ProbDef3Y)

 

        yield = Cells(i, Col_YTM)

          

            If Cells(i + 1, Col_YTM) > Cells(i, Col_YTM) Then yield = Cells(i + 1, Col_YTM)

      i = i + 1

    Wend



###########Mon problème est ici################



Set yield = Range("W2:W600").Cells.Find(yield, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)

'Row_yield = yield.Row

    'l = yield.Rows



Rows(l).Select

#################################################"

Selection.Copy



With Sheets("Portefeuille final")



Rows("2:2").Select

    Selection.Insert Shift:=xlDown

End With





Next i

MsgBox ("Macro finie")



End Sub
 
Dernière édition:

Discussions similaires

Réponses
8
Affichages
472

Statistiques des forums

Discussions
312 100
Messages
2 085 292
Membres
102 852
dernier inscrit
Badrcola26