1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| Private Function GetRangeGoal(pSheet As Worksheet, pValue As String) As Range
Dim oRange As Range
' Désactive tous les filtres éventuels
pSheet.ShowAllData
Set oRange = pSheet.UsedRange
' Recherche la valeur
Set GetRangeGoal = oRange.Find(What:=pValue, LookAt:=xlWhole, MatchCase:=True)
' Si la valeur est trouvée, renvoi de la ligne complète pour avoir l'ensemble des données
If Not GetRangeGoal Is Nothing Then
Set GetRangeGoal = GetRangeGoal.EntireRow
End If
Set oRange = Nothing
End Function
Private Function SearchRowInOrigine(ByVal pCriteria As String) As Range
Dim oSheetOrigine As Worksheet
Dim oRangeOrigine As Range
Dim lRow As Integer
' Récupération de la feuille d'origine sur laquelle on recherche la valeur
Set oSheetOrigine = ActiveWorkbook.Worksheets("2010")
Set oRangeOrigine = GetRangeGoal(oSheetOrigine, pCriteria)
' Recherche la ligne correspondante au critère passé en paramètre
' Si la ligne est trouvée, renvoi de la ligne complète
If Not oRangeOrigine Is Nothing Then
' Complétion des critères
If oSheetOrigine.Cells(oRangeOrigine.Row, 9) = "STD" And _
oSheetOrigine.Cells(oRangeOrigine.Row, 17) = pCriteria And _
oSheetOrigine.Cells(oRangeOrigine.Row, 24) > "0" Then
' Renvoi de la ligne complète
Set SearchRowInOrigine = oSheetOrigine.Cells(oRangeOrigine.Row, 1).EntireRow
End If
End If
Set oRangeOrigine = Nothing
Set oSheetOrigine = Nothing
End Function
Private Function SearchRowInDestination(ByVal pCriteria As String) As Range
Dim oSheetDestination As Worksheet
Dim oRangeDestination As Range
Dim lRow As Integer
Set oSheetDestination = ActiveWorkbook.Worksheets("std")
Set oRangeDestination = GetRangeGoal(oSheetDestination, pCriteria)
' Recherche la ligne correspondante au critère passé en paramètre
' Si la ligne est trouvée, renvoi de la ligne complète
If Not oRangeDestination Is Nothing Then
If oSheetDestination.Cells(oRangeDestination.Row, 9) = "STD" And _
oSheetDestination.Cells(oRangeDestination.Row, 17) = pCriteria Then
' Renvoi de la ligne complète
Set SearchRowInDestination = oSheetDestination.Cells(oRangeDestination.Row, 1).EntireRow
End If
End If
Set oRangeDestination = Nothing
Set oSheetDestination = Nothing
End Function
Public Sub Test()
Dim oSheetDestination As Worksheet
Dim oRange1 As Range
Dim oRange2 As Range
Dim lRowIndex As Integer
Dim Valeutr As Variant
valeur = InputBox("Entrée période", "Choix de la période")
If valeur = "" Then Exit Sub
Set oRange1 = SearchRowInOrigine("P03/10")
If Not oRange1 Is Nothing Then
Set oSheetDestination = ActiveWorkbook.Worksheets("std")
Set oRange2 = SearchRowInDestination("P03/10")
If Not oRange2 Is Nothing Then
'Index de la ligne a remplacer
lRowIndex = oRange2.Row
Else
'Index de la nouvele ligne
lRowIndex = oSheetDestination.Range(oSheetDestination.Range("A65000").Address).End(xlUp).Row + 1
End If
With oSheetDestination
.Cells(lRowIndex, 1).Value = oRange1.Cells(1, 2).Value
.Cells(lRowIndex, 2).Value = oRange1.Cells(1, 7).Value
.Cells(lRowIndex, 3).Value = oRange1.Cells(1, 8).Value
.Cells(lRowIndex, 6).Value = oRange1.Cells(1, 10).Value
.Cells(lRowIndex, 8).Value = oRange1.Cells(1, 12).Value
.Cells(lRowIndex, 17).Value = oRange1.Cells(1, 17).Value
.Cells(lRowIndex, 13).Value = oRange1.Cells(1, 24).Value
.Cells(lRowIndex, 9).Value = oRange1.Cells(1, 9).Value
.Cells(lRowIndex, 10).Value = oRange1.Cells(1, 29).Value
' Je ne comprends pas bien pourquoi tu fais ça
.Cells(lRowIndex, 4).Value = UCase(.Cells(lRowIndex, 1).Value) & UCase(.Cells(lRowIndex, 2).Value)
.Cells(lRowIndex, 4).Value = Replace(Cells(lRowIndex, 3).Value, " ", "")
End With
Set oSheetDestination = Nothing
End If
Set oRange1 = Nothing
Set oRange2 = Nothing
End Sub |
Partager