La dernière non vide (VBA)
Cette question peut être interprétée de différentes façons (voir l'exemple joint à télécharger). Teste donc ces différentes solutions et choisis celle qui te convient le mieux:
Une formule matricielle ( à valider par ctrl+maj.entrée)
=ADRESSE(MAX(SI(Plage<>"";LIGNE(Plage)));MAX(SI(Plage<>"";COLONNE(Plage))))
Une autre :
=ADRESSE(MAX(SI(Plage<>"";LIGNE(Plage)));MAX(SI(Plage<>"";SI(LIGNE(Plage)=MAX(SI(Plage<>"";LIGNE(Plage)));COLONNE(Plage)))))
Une fonction VBA :
Function DerCell_NonVide(Plg As Range) As String
Dim DerLig As Long, DerCol As Integer
DerLig = Cells.Find("*", LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
DerCol = Plg.Find("*", LookIn:=xlValues, _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
DerCell_NonVide = Cells(DerLig, DerCol).Address
End FunctionTu peux utiliser cette fonction dans la feuille de calcul : =DerCell_NonVide(A1:H30) ou en VBA :
sub test()
With Worksheets("Feuil1")
MsgBox DerCell_NonVide(.Range("A1:H30"))
End With
end subautre solution :
sub dernièreligne()
Set x = [D9:Z30].Find("*", , xlValues, , xlByRows, xlPrevious)
MsgBox x.Address
end subsub dernièreColonne()
Set x = [A1:H30].Find("*", , xlValues, , xlByColumns, xlPrevious)
MsgBox x.Address
end subsub IntersectionDerLigneColonne()
x = Cells([A1:H30].Find("*", , xlValues, , xlByRows, xlPrevious).Row,
[D9:Z58].Find("*", , xlValues, , xlByColumns, xlPrevious).Column).Address
MsgBox x
end subou bien encore :
If Not IsError([z]) Then Names("z").Delete
Names.Add Name:="z", RefersTo:="=MAX(IF(A1:H30<>"""",ROW(A1:H30)))" MsgBox [z]
pour l'adresse de la cellule à l'intersection de la dernière ligne et de la dernière colonne,
If Not IsError([k]) Then Names("k").Delete
ActiveWorkbook.Names.Add Name:="k", RefersTo:= _ "=ADDRESS(MAX(IF(Feuil2!$9:$58<>"""",ROW(Feuil2!$9:$58))),MAX(IF(Feuil2!$9:$58<>"""",COLUMN(Feuil2!$9:$58))))"
MsgBox [k]Et encore :
sub Evaluate_AV() MsgBox [address(max(if(Plage<>"",row(plage))),max(if(Plage<>"",if(row(Plage)=max(if(Plage<>"",row(Plage))),column(Plage)))))] end sub
Astuce illustrée par ce classeur
av-lesdernieres
Auteurs : isabelle, Jacques Boisgontier, Denis Michon, Alain Vallon
Mots clefs associés à cette page : dernier, dernière, vba, vbe, vide
- Vous devez vous identifier ou créer un compte pour écrire des commentaires
