Bonjour le forum,
j'ai récupéré le code ci dessous sur le site, mais je n'arrive pas à le modifier selon mon besion.
la macro ci dessous me donne bien le numéro de page de la cellule, mais via un message, est ce qu'il est possible d'inserer le résultat dans la cellule selon la matrice jointe.
merci de votre aide, cdt
Sub numeroPageCelluleActive()
Application.ScreenUpdating = False
ActiveWindow.View = xlPageBreakPreview
MsgBox numeroPage(ActiveCell)
ActiveWindow.View = xlNormalView
Application.ScreenUpdating = True
End Sub
Function numeroPage(Cellule As Range) As Integer
Dim VPC As Integer, HPC As Integer
Dim VPB As VPageBreak, HPB As HPageBreak
Dim Wksht As Worksheet
Dim Col As Integer, Ligne As Long
Set Wksht = Cellule.Worksheet
Ligne = Cellule.Row
Col = Cellule.Column
If Wksht.PageSetup.Order = xlDownThenOver Then
HPC = Wksht.HPageBreaks.Count + 1
VPC = 1
Else
VPC = Wksht.VPageBreaks.Count + 1
HPC = 1
End If
numeroPage = 1
For Each VPB In Wksht.VPageBreaks
If VPB.Location.Column > Col Then Exit For
numeroPage = numeroPage + HPC
Next VPB
For Each HPB In Wksht.HPageBreaks
If HPB.Location.Row > Ligne Then Exit For
numeroPage = numeroPage + VPC
Next HPB
End Function
j'ai récupéré le code ci dessous sur le site, mais je n'arrive pas à le modifier selon mon besion.
la macro ci dessous me donne bien le numéro de page de la cellule, mais via un message, est ce qu'il est possible d'inserer le résultat dans la cellule selon la matrice jointe.
merci de votre aide, cdt
Sub numeroPageCelluleActive()
Application.ScreenUpdating = False
ActiveWindow.View = xlPageBreakPreview
MsgBox numeroPage(ActiveCell)
ActiveWindow.View = xlNormalView
Application.ScreenUpdating = True
End Sub
Function numeroPage(Cellule As Range) As Integer
Dim VPC As Integer, HPC As Integer
Dim VPB As VPageBreak, HPB As HPageBreak
Dim Wksht As Worksheet
Dim Col As Integer, Ligne As Long
Set Wksht = Cellule.Worksheet
Ligne = Cellule.Row
Col = Cellule.Column
If Wksht.PageSetup.Order = xlDownThenOver Then
HPC = Wksht.HPageBreaks.Count + 1
VPC = 1
Else
VPC = Wksht.VPageBreaks.Count + 1
HPC = 1
End If
numeroPage = 1
For Each VPB In Wksht.VPageBreaks
If VPB.Location.Column > Col Then Exit For
numeroPage = numeroPage + HPC
Next VPB
For Each HPB In Wksht.HPageBreaks
If HPB.Location.Row > Ligne Then Exit For
numeroPage = numeroPage + VPC
Next HPB
End Function
Pièces jointes
Dernière édition: