Modification d'une Macro

Luni

XLDnaute Junior
;)Bonjour à tous et à toutes,

Je voudrais modifier cette macro mais je n'ai jamais fait ce genre de modification et je ne sais pas comment faire. Actuellement cette macro utilise la feuil1 et la feuil2 et je voudrais qu'elle utilise toujours la feuil1 mais la feuil2 a été déplacée sur un autre classeur qui s'appelle "Données 2011" sur la feuil 6 et je ne sais pas comment faire. J'utilise récemment excel 2007 (si jamais) merci beaucoup.


Il semblerait qu'avec 2007 je dois éviter d'avoir une macro qui contient .Range("B65536").End(xlUp) pourquoi ? Que puis-je mettre à la place?



Option Explicit

Sub Commentaires()
Dim Lg01 As Long
Dim Lg02 As Long
Dim Lg As Long
Dim Cl01 As Long
Dim Cel As Range
Dim Mot As String
Dim Nom As String
Dim Num As Integer

Dim I As Long
' Abs Hor Vac Rec
Mot = "AbsHorVacRec"

Feuil1.Cells.ClearComments
With Feuil2
For Lg02 = 10 To .Range("B65536").End(xlUp).Row
If .Cells(Lg02, 2) <> "" Then
Num = .Cells(Lg02, 2)
Lg01 = 0
With Feuil1
Set Cel = .Range("B10:B" & .Range("B65536").End(xlUp).Row).Find(what:=Num, LookIn:=xlValues, lookat:=xlWhole)
If Not Cel Is Nothing Then
Lg01 = Cel.Row
End If
End With
If Lg01 <> 0 Then
Lg = Lg02
While .Cells(Lg, 15) <> ""
Cl01 = 1 + (.Cells(Lg, 15) * 4) + Int(InStr(1, Mot, .Cells(Lg, 13)) / 3)
Nom = .Cells(Lg, 16) & "/" & .Cells(Lg, 17) & "/" & .Cells(Lg, 18)
While Right(Nom, 1) = "/"
Nom = Left(Nom, Len(Nom) - 1)
Wend
With Feuil1.Cells(Lg01, Cl01)
If .Comment Is Nothing Then
.AddComment ' Création commentaire
.Comment.Text Text:="Info:" & vbLf ' Initialisation
End If
.Comment.Text Text:=.Comment.Text & Nom & vbLf
.Comment.Shape.TextFrame.AutoSize = True
End With
Lg = Lg + 1
Wend
End If
End If
Next Lg02
End With

End Sub
 
Dernière édition:

Papou-net

XLDnaute Barbatruc
Re : Modification d'une Macro

Bonjour Luni,

Si ton autre classeur est ouvert, essaie en remplçant "With Feuil2" par "With "Workbooks("Données 2011").Sheets("Feuil6").

La seule contre-indication d'écrire ".Range("B65536").End(xlUp) " est que, depuis la version 2007, Excel intègre un nombre de lignes beaucoup plus important (+ de 1 million, je crois). Donc si ta feuille comporte plus de 65536 lignes renseignées, le résultat risquera d'être faussé si tu veux obtenir le n° de la dernière ligne de ton tableau. Tu dois donc remplacer 65536 par le nombre de lignes maxi autorisé par XL2007.

Espérant avoir répondu.

Cordialement.
 

Discussions similaires

Statistiques des forums

Discussions
312 429
Messages
2 088 351
Membres
103 824
dernier inscrit
frederic.marien@proximus.