Cmt lancer une procedure VBA sur 1 autre onglet?

F

François

Guest
Bonjour,

Voici mon code VBA dans EXCEL:
Code:
Public Sub STDEVFUNCTION() 
    iLastRow = Range('A65536').End(xlUp).Row 
    iLastRow2 = iLastRow - 1 
    sResults = 'B3:B' & iLastRow2 
    iLastRow = Range('A1').CurrentRegion.Rows.Count + 1 
    iLastColumn = Range('A1').CurrentRegion.Columns.Count 
    Cells(iLastRow, 2) = '=STDEV(' & sResults & ')' 
    Range('B' & iLastRow).Copy Range('B' & iLastRow).Resize(1, iLastColumn - 1) 
    Range('B' & iLastRow).Resize(1, iLastColumn - 1).Value = Range('B' & iLastRow).Resize(1, iLastColumn - 1).Value 
End Sub 

Private Sub CommandButton1_Click() 
STDEVFUNCTION 
End Sub


il fonctionne sur l'onglet où est disposé le bouton de commande
mais le range est celui d'un autre onglet appelé 'TP_REPEAT'
Comment modifier mon code?

merci d'avance,

Salutations
 

CBernardT

XLDnaute Barbatruc
Bonjour François,

Tu conserves la macro du bouton dans le module de feuille :

Private Sub CommandButton1_Click()
STDEVFUNCTION
End Sub

Tu places la macro d'exécution dans un module standard:

Sub STDEVFUNCTION()
Dim iLastRow As Integer
Dim iLastColumn As Byte
Dim sResults As Variant

iLastRow = Range('A65536').End(xlUp).Row - 1
sResults = Range('B3:B' & iLastRow)

With Sheets('TP_REPEAT')
iLastRow = .Range('A1').UsedRange.Rows.Count + 1
iLastColumn = .Range('A1').UsedRange.Columns.Count
.Cells(iLastRow, 2) = '=STDEV(' & sResults & ')'
.Range('B' & iLastRow).Copy .Range('B' & iLastRow).Resize(1, iLastColumn - 1)
.Range('B' & iLastRow).Resize(1, iLastColumn - 1).Value = .Range('B' & iLastRow).Resize(1, iLastColumn - 1).Value
End With
End Sub

Cordialement

Bernard
 

Discussions similaires

Réponses
6
Affichages
142
Réponses
6
Affichages
248

Statistiques des forums

Discussions
312 329
Messages
2 087 329
Membres
103 517
dernier inscrit
hbenaoun63