Sub MatchLiquor() Dim lastRowOne As Long Dim lastRowTwo As Long Dim sheetNameOne As Ssortingng Dim sheetNameTwo As Ssortingng sheetNameOne = "Recipies" 'Recipies Sheet sheetNameTwo = "Liquor Breakdowns" 'Liquor Breakdowns lastRowOne = Sheets(sheetNameOne).Range("B" & Rows.Count).End(xlUp).Row lastRowTwo = Sheets(sheetNameTwo).Range("A" & Rows.Count).End(xlUp).Row For lRow = 2 To lastRowOne 'Loop through all rows For lRowTwo = 2 To lastRowTwo 'Loop through all rows If Sheets(sheetNameOne).Cells(lRow, "B") = Sheets(sheetNameTwo).Cells(lRowTwo, "A") Then Sheets(sheetNameOne).Cells(lRow, "C") * Sheets(sheetNameOne).Cells(lRowTwo, "E") Then End If Next lRowTwo Next lRow End Sub
En sudo, ce que je tente d'accomplir est tel: searchz toutes les lignes de la feuilleA pour "nom" et comparez à la fiche "nom". En cas de résultat, multipliez la valeur différente en feuilleA par une valeur différente dans la feuille B; des valeurs de sortie dans différentes cellules dans la feuille A (exemple E).
Je n'ai pas encore compris comment sortir, ou même si cela fonctionnera. Des idées?
Il y a eu une certaine confusion quant à savoir quelles feuilles de travail ont été utilisées là où et aucune cible pour le produit sur une correspondance a été fournie, mais cela devrait éclaircir vos loops.
Sub MatchLiquor() Dim lastRowOne As Long, lastRowTwo As Long, prodct As Double Dim sheetNameOne As Ssortingng, sheetNameTwo As Ssortingng sheetNameOne = "Recipies" 'Recipies Sheet sheetNameTwo = "Liquor Breakdowns" 'Liquor Breakdowns With Sheets(sheetNameOne) lastRowOne = .Range("B" & Rows.Count).End(xlUp).Row lastRowTwo = Sheets(sheetNameTwo).Range("A" & Rows.Count).End(xlUp).Row For lRow = 2 To lastRowOne 'Loop through all rows on Recipies Sheet For lRowTwo = 2 To lastRowTwo 'Loop through all rows on Liquor Breakdowns If .Cells(lRow, "B") = Sheets(sheetNameTwo).Cells(lRowTwo, "A") Then prodct = .Cells(lRow, "C").Value * Sheets(sheetNameTwo).Cells(lRowTwo, "E").Value 'do something with prodct .cells(lRow, "E") = prodct Exit For 'found match and computed product; no need to continue this lRowTwo End If Next lRowTwo Next lRow End With End Sub
Si une correspondance a été trouvée et un produit calculé (et mis quelque part), il n'est pas nécessaire de continuer à parcourir la boucle nestede interne avec lRowTwo
. Just Exit For
qui vous ramènera à la boucle extérieure et à la prochaine lRow
.
Utilisation des Sheets(sheetNameOne)
dans une version de … Terminer avec diminue les references de la feuille de travail principale à la moitié.