Private Function cherche1(feuille As Worksheet, strRMois As String, strRNom As String, _ strNomColVal As String, ColMois As String, ColNom As String) As String cherche1 = "Pas de données" Dim strNomColMois, strNomColNom If ColMois "" Then strNomColMois "Mois" If ColNom "" Then strNomColNom "Nom" 'Trouver les numéros des colonne Utilisés Dim intNColNom As Integer, intNColVal As Integer, intNColMois As Integer Dim c As Range With feuille With .Rows(1) Set c = .Find(strNomColNom, LookIn:=xlValues, lookat:=xlWhole) If Not c Is Nothing Then intNColNom = c.Column Set c = .Find(strNomColVal, LookIn:=xlValues, lookat:=xlWhole) If Not c Is Nothing Then intNColVal = c.Column Set c = .Find(strNomColMois, LookIn:=xlValues, lookat:=xlWhole) If Not c Is Nothing Then intNColMois = c.Column End With Dim intNLigne As Variant intNLigne = feuille.Cells(Rows.Count, intNColMois).End(xlUp).Row With feuille.Range(Cells(1, intNColMois), Cells(intNLigne, intNColMois)) Dim firstaddress As String Set c = .Find(strRMois, LookIn:=xlValues, lookat:=xlWhole) If Not c Is Nothing Then If feuille.Cells(c.Row, intNColNom).Text = strRNom Then cherche1 = feuille.Cells(c.Row, intNColVal).Value: Exit Function End If firstaddress = c.Address Do Set c = .FindNext(c) If Not c Is Nothing And .Cells(c.Row, intNColNom).Text = strRNom Then cherche1 = feuille.Cells(c.Row, intNColVal).Value: Exit Function End If Loop While Not c Is Nothing And c.Address <> firstaddress End If End With End With End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionWith .Range(Cells(1, intNColMois), Cells(intNLigne, intNColMois))
With .Range(.Cells(1, intNColMois), .Cells(intNLigne, intNColMois))
With feuille.Range(Cells(1, 1), Cells(1, 2))
With feuille.Range(.Cells(1, intNColmois), .Cells(derligne, intNColmois))
Private Function cherche1(feuille As Worksheet, strRMois As String, strRNom As String, _ strNomColVal As String, ColMois As String, ColNom As String) As String
Private Function cherche1(strRMois As String, strRNom As String, _ strNomColVal As String, ColMois As String, ColNom As String) As String Dim feuille As Worksheet Set feuille = Application.Caller.Parent 'évidemment si la recherche s'effectue toujours dans la feuille appelante
Private Function cherche1(ByVal strRMois As String, ByVal strRNom As String, _ ByVal strNomColVal As String, ByVal ColMois As String, ByVal ColNom As String) As String
Dim strNomColMois, strNomColNom If ColMois "" Then strNomColMois "Mois" If ColNom "" Then strNomColNom "Nom"
Private Function cherche1(ByVal strRMois As String, ByVal strRNom As String, _ ByVal strNomColVal As String,Optional ByVal ColMois As String "Mois", Optional ByVal ColNom As String "Nom") As String
If nomcolnoms "" then nomcolnoms "Nom" If nomcolmois "" then nomcolmois "Mois"
If nomcolnoms "" then nomcolnoms "Nom"
If nomcolmois "" then nomcolmois "Mois"