Figer cellules et Lignes dans Macro

Bonjour à tous,

Je sollicite votre aide car, malgré de nombreuses recherches, je n'arrive pas à trouver la solution à mon problème.

J'ai une macro qui me permet de faire une recherche dans une base de données, et d'afficher un ID en fonction d'une référence, de plusieurs dates, et dès qu'il voit un bout de texte la macro sait qu'il faut l'afficher à partir de là. Bref, peut-être qu'avec la macro vous comprendrez mieux ^^

Peut-être que ça va vous sembler simple mais j'avoue que je ne maîtrise pas trop les macros (et oui je débute là-dessus ...)

Mon problème: Ma macro saute à chaque fois que j'ajoute ou supprime une ligne ou une colonne (surtout les lignes), de ce fait, je souhaiterais trouver une solution pour que ma macro soit toujours opérationnelle sans que j'ai à la maintenir (dans le sens où je ne veux pas devoir modifier les n° de lignes à chaque fois que je supprime ou que j'ajoute une ligne).

De ce fait, je souhaite figer 3 cellules (en rouge dans la macro) et 2 lignes (en vert dans la macro). Je fais plusieurs fois allusions aux cellules ou aux lignes dans la macro.

D'après ce que j'ai compris, en renommant les cellules, cela permet de corriger mon problème.

Cependant, je n'arrive pas à intégrer la cellule renommée dans la macro, et, je sais pas si on peut renommer une ligne ...

Voici la macro:

Sub AZmois1()
'
'Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'###########
Dim DelSO_ids() As String
ReDim DelSO_ids(1)
'###########
Dim SO_ids() As String
ReDim SO_ids(1)
Dim PO_ids() As String
ReDim PO_ids(1)
Dim i As Integer, j As Integer, k As Integer
Dim Id As String
Dim BrandWksIndex As Integer
BrandWksIndex = ActiveSheet.Index
Dim datemin As Long, datemax As Long
Cells([color=#FF4000]102, 12[/color]).Calculate
Cells([color=#FF4000]103, 12[/color]).Calculate
Cells([color=#FF4000]104, 12[/color]).Calculate
datemin = CLng(Cells([color=#FF4000]103, 12[/color]))
datemax = CLng(Cells([color=#FF4000]104, 12[/color]))
Dim Brand As String
Brand = WkstToBrand()
Dim Message As String

'Find relevant SOs
i = 3
Do
    If Worksheets("SO").Cells(i, 7) Like Brand Then
        If CLng(Worksheets("SO").Cells(i, 17).Value) >= datemin And CLng(Worksheets("SO").Cells(i, 17).Value) <= datemax Then
            If Worksheets("SO").Cells(i, 4) = "#" Then
                Id = Worksheets("SO").Cells(i, 3)
                If SO_ids(1) = "" Then
                    SO_ids(1) = Id
                ElseIf IsNewData(SO_ids, Id) = True Then
                    ReDim Preserve SO_ids(UBound(SO_ids) + 1)
                    SO_ids(UBound(SO_ids)) = Id
                End If
            Else
                Id = Worksheets("SO").Cells(i, 3)
                If DelSO_ids(1) = "" Then
                    DelSO_ids(1) = Id
                ElseIf IsNewData(DelSO_ids, Id) = True Then
                    ReDim Preserve DelSO_ids(UBound(DelSO_ids) + 1)
                    DelSO_ids(UBound(DelSO_ids)) = Id
                End If
            End If
        End If
    End If
    i = i + 1
Loop While Worksheets("SO").Cells(i, 1) <> ""

'Find relevant POs
i = 3
Do
    If Worksheets("PO").Cells(i, 6) Like Brand Then
        If CLng(Worksheets("PO").Cells(i, 15).Value) >= datemin And CLng(Worksheets("PO").Cells(i, 15).Value) <= datemax Then
            Id = Worksheets("PO").Cells(i, 1)
            If PO_ids(1) = "" Then
                PO_ids(1) = Id
            ElseIf IsNewData(PO_ids, Id) = True Then
                ReDim Preserve PO_ids(UBound(PO_ids) + 1)
                PO_ids(UBound(PO_ids)) = Id
            End If
        End If
    End If
    i = i + 1
Loop While Worksheets("PO").Cells(i, 1) <> ""

'Place relevant Delivered SOs
i = 1
j = 1
k = 0
Do
    If Worksheets(BrandWksIndex).Cells([color=#00BF00]108, i[/color]).Value = "SALES DELIVERED TO" Then
        k = k + 1
        If j <= UBound(DelSO_ids) And DelSO_ids(1) <> "" Then
            Worksheets(BrandWksIndex).Cells([color=#00BF00]110, i[/color]) = DelSO_ids(j)
            j = j + 1
        Else
            Worksheets(BrandWksIndex).Cells([color=#00BF00]110, i[/color]) = ""
        End If
    End If
    i = i + 1
Loop While i < 200
If k < UBound(SO_ids) Then Message = "Veuillez ajouter des colonnes 'Delivered SO'"

'Place relevant SOs
i = 1
j = 1
k = 0
Do
    If Worksheets(BrandWksIndex).Cells([color=#00BF00]108, i[/color]).Value = "SALES TO" Then
        k = k + 1
        If j <= UBound(SO_ids) And SO_ids(1) <> "" Then
            Worksheets(BrandWksIndex).Cells([color=#00BF00]110, i[/color]) = SO_ids(j)
            j = j + 1
        Else
            Worksheets(BrandWksIndex).Cells([color=#00BF00]110, i[/color]) = ""
        End If
    End If
    i = i + 1
Loop While i < 200
If k < UBound(SO_ids) Then Message = Message & vbCr & "Veuillez ajouter des colonnes 'SO'"

'Place relevant POs
i = 1
j = 1
k = 0
Do
    If Left(Worksheets(BrandWksIndex).Cells([color=#00BF00]108, i[/color]).Value, 8) = "PURCHASE" Then
        k = k + 1
        If j <= UBound(PO_ids) And PO_ids(1) <> "" Then
            Worksheets(BrandWksIndex).Cells([color=#00BF00]110, i[/color]) = PO_ids(j)
            j = j + 1
        Else
            Worksheets(BrandWksIndex).Cells([color=#00BF00]110, i[/color]) = ""
        End If
    End If
    i = i + 1
Loop While i < 200
If k < UBound(PO_ids) Then Message = Message & vbCr & "Veuillez ajouter des colonnes 'PO'"

Application.ScreenUpdating = True
If Message <> "" Then MsgBox Message

Application.Calculation = xlAutomatic

End Sub

En fait, je veux remplacer les cellules:

  • (102 , 12) par AZ_11
  • (103 , 12) par AZ_12
  • (104 , 12) par AZ_13

Et, je veux remplacer les lignes:

  • 108 par AZ_14
  • 110 par AZ_15

Si quelqu'un pouvait m'aider ça serait vraiment très gentil!

Merci!

Bonsoir,

je viens de lire et j'ai du mal à accrocher...

Un fichier serait le bienvenu.

@ bientôt

LouReeD

Bonjour,

un exemple avec ce que j'ai compris (utiliser des cellules ou plages nommées) :

[AZ_11].Calculate
'version abrégée de :
Range("AZ_11").Calculate

eric

Rechercher des sujets similaires à "figer lignes macro"