Formulaire et macro

Ddaniell

XLDnaute Nouveau
Bonjour

Je suis entrain de créer un formulaire avec plusieurs macros. Dans mon formulaire, j'ai inclus trois tableaux, les macros servent à ajouter des lignes à chaque tableau, donc trois macros (une par tableau).

Pour le premier tableau, la macro fonctionne très bien, les lignes s'ajoutent correctement. Mon problème survient avec le deuxième tableau (et le trois aussi). Si aucune ligne n'a été ajoutée au tableau #1, la macro du tableau #2 fonctionne correctement. Par contre, si des lignes ont été ajoutées au tableau #1, lorsque j,active la macro du tableau #2, les ligne sont décalées puisque la macro est reliée à une ligne spécifique.

Par exemple, quand je vais la macro pour le tableau #2, j'ajoute la ligne à la ligne 20. Par contre, si j'ajoute des lignes au tableau #1, la ligne 20 n'est plus à la même place donc la ligne apparait à la mauvaise place.

J'espère avoir été clair.

Pouvez-vous m'aider?

Dan.
 

mromain

XLDnaute Barbatruc
Re : Formulaire et macro

bonjour Ddaniell, keepcool183,

je te propose ces trois macros pour les trois boutons :
Code:
Sub ajout1()
Dim cellFind As Range
Set cellFind = Range("A:A").Find("Sub-total/ Sous total", , xlValues, xlWhole)
If Not cellFind Is Nothing Then
    Rows(cellFind.Row - 1).Insert
End If
End Sub

Sub ajout2()
Dim cellFind As Range
Set cellFind = Range("A:A").Find("Sub-total/ Sous total", , xlValues, xlWhole)
Set cellFind = Range("A:A").FindNext(cellFind)
If Not cellFind Is Nothing Then
    Rows(cellFind.Row - 1).Insert
End If
End Sub

Sub ajout3()
Dim cellFind As Range
Set cellFind = Range("A:A").Find("Sub-total/ Sous total", , xlValues, xlWhole)
Set cellFind = Range("A:A").FindNext(cellFind)
Set cellFind = Range("A:A").FindNext(cellFind)
If Not cellFind Is Nothing Then
    Rows(cellFind.Row - 1).Insert
End If
End Sub

a+
 

mromain

XLDnaute Barbatruc
Re : Formulaire et macro

re,

à tester :
Code:
Sub ajout1()
Dim cellFind As Range
Set cellFind = Range("A:A").Find("Sub-total/ Sous total", , xlValues, xlWhole)
If Not cellFind Is Nothing Then
    Rows(cellFind.Row - 1).Insert
    MiseEnFormeTableau Range(Cells(10, 1), Cells(cellFind.Row - 2, 4))
End If
End Sub

Sub ajout2()
Dim cellFind As Range, i As Integer
Set cellFind = Range("A:A").Find("Sub-total/ Sous total", , xlValues, xlWhole)
If Not cellFind Is Nothing Then i = cellFind.Row + 5
Set cellFind = Range("A:A").FindNext(cellFind)
If Not cellFind Is Nothing Then
    Rows(cellFind.Row - 1).Insert
    If Not i = Empty Then MiseEnFormeTableau Range(Cells(i, 1), Cells(cellFind.Row - 2, 4))
End If
End Sub

Sub ajout3()
Dim cellFind As Range
Set cellFind = Range("A:A").Find("Sub-total/ Sous total", , xlValues, xlWhole)
Set cellFind = Range("A:A").FindNext(cellFind)
If Not cellFind Is Nothing Then i = cellFind.Row + 5
Set cellFind = Range("A:A").FindNext(cellFind)
If Not cellFind Is Nothing Then
    Rows(cellFind.Row - 1).Insert
    If Not i = Empty Then MiseEnFormeTableau Range(Cells(i, 1), Cells(cellFind.Row - 2, 4))
End If
End Sub


Sub MiseEnFormeTableau(tableau As Range)
With tableau.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With tableau.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With tableau.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With tableau.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With tableau.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlHairline
End With
With tableau.Borders(xlInsideHorizontal)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlHairline
End With
End Sub

a+
 

mromain

XLDnaute Barbatruc
Re : Formulaire et macro

re,

bizarre,
ça marche chez moi (Excel 2007)

je t'envoie le fichier...

a+
 

Pièces jointes

  • Formulaire.zip
    15.2 KB · Affichages: 28
  • Formulaire.zip
    15.2 KB · Affichages: 31
  • Formulaire.zip
    15.2 KB · Affichages: 29

mromain

XLDnaute Barbatruc
Re : Formulaire et macro

bonjour Ddaniell,

je ne peux pas voir du coup.
faut espérer qu'une âme charitable qui passe par là avec Excel2003 te le débugge...

PS: le fichier que je t'ai envoyé sur mon dernier post ne marche pas non plus ?

a+
 

Discussions similaires

Réponses
17
Affichages
790

Statistiques des forums

Discussions
312 497
Messages
2 088 994
Membres
104 000
dernier inscrit
dinelcia