Afwijking in uitvoering Macro

KeBr

Gebruiker
Lid geworden
25 apr 2016
Berichten
164
Beste forumleden,

Ik heb een vraag, niet direct over VBA zelf maar over het resultaat van een Macro.
Als ik de macro zelf uitvoer staat alles netjes op zijn plaats. Als een collega met hetzelfde besturingssysteem en zelfde versie van Excel deze macro uitvoert ontstaan er afwijkingen. zie onderstaande afbeeldingen. bovenste heb ik zelf gedaan onderste door een collega. Ook zie ik dat hoe verder omlaag in de planning de afwijking steeds groter wordt.
Heeft iemand een idee waar dit aan ligt?
1712911234355.png

1712911129315.png
 
is dit in gedeelde file of heeft ieder een eigen versie?
 
Dit is in een gedeelde file. Het is zelf zo dat wanneer wij er samen inzitten en ik de macro uitvoer alles goed gaat. Als mijn collega het doet zie ik het gewoon fout gaan.
We gebruiken beide office 365. Wel hebben we allemaal onze eigen office installatie op de pc staan.
Ook hebben de meeste van mij collega's natuurlijk niet het tabblad ontwikkelaars aanstaan.
 
het is niet zo dat er ergens autofit voor de kolombreedtes in je VBA wordt toegepast.
Hoe staan de eigenschappen voor die dubbele pijlen
1712937793272.png
 
Hieronder de gehele code die ik gebruik. De dubbele pijlen zijn dan met de vetgedrukte regels.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ShpNum As String
Dim Dupl  As Shape, NewShp As Shape


Sheets("Projectplanning").Unprotect Password:=Wachtwoord()

    'Controleer of  E, F en I datumkolommen zijn. zo niet sla dan over.
If Intersect(Target, Range("C8:I300")) Is Nothing Then Exit Sub 'Edit 8 & or 300 if inappropriate
'Check if more than one cell and ignore if yes
If Target.Count > 1 Then Exit Sub

'Otherwise...
r = Target.Row
' ignore if an empty Column C in row
If Cells(r, 7) = "" Then Exit Sub

'otherwise a date has been changed

ShpName = "SHP_" & Cells(r, 7) 'Shape Name
'Delete current shape of that name if it exists
For Each xshape In Shapes
    If xshape.TopLeftCell.Row = Target.Row Then xshape.Delete
Next
    'get equal date  cells
   LftCell = Cells(r, 5) - Cells(6, 5) + 18
   RtCell = Cells(r, 6) - Cells(6, 5) + 18
        
  x = Application.Match(Cells(r, 3), Sheets("Gegevens").Columns(5), 0)
  If IsNumeric(x) Then fc = RGB(Sheets("Gegevens").Cells(x, 6), Sheets("Gegevens").Cells(x, 7), Sheets("Gegevens").Cells(x, 8))

Select Case Cells(r, 7).Value
 
Case Is <= 0
    'diamond for Milestone date
    Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeDiamond, Cells(r, LftCell).Left, Cells(r, LftCell).Top + 2, Cells(r, LftCell).Width, Cells(r, LftCell).Height - 4)
          NewShp.Fill.ForeColor.RGB = fc
            NewShp.Line.ForeColor.RGB = fc
          
Case Is = "M" 'Speciale aanduiding voor Meetings
          ActiveCell.Offset(-1, 0).Select
          On Error Resume Next
                                      
                   For d1 = Application.InputBox("geef startdatum", Type:=1) To Application.InputBox("geef einddatum", Type:=1) Step InputBox("geef interval") 'ergens een gek interval opzetten = om de 3 dagen
                    r = Application.Match(d1, ActiveSheet.Rows(6), 0) 'zoek die dag op in de rij 6
                        If IsNumeric(r) Then 'gevonden
                             Set C = ActiveSheet.Cells(ActiveCell.Row, r) 'in deze cel komt je shape
                             If NewShp Is Nothing Then 'het is de eerste shape
                                  Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeRightTriangle, C.Left + 1, C.Top + 1, C.Width - 2, C.Height - 2)     'beginshape
                                    NewShp.Fill.ForeColor.RGB = fc
                                    NewShp.Line.ForeColor.RGB = fc
                                  NewShp.Name = "SHP_"
                             Else
                                  Set Dupl = Nothing
                                  Set Dupl = NewShp.Duplicate     'eerste shape dupliceren
                                  DoEvents
    
                                  With Dupl      'die shape
                                       .Left = C.Left + 1     'verplaatsen
                                       .Top = C.Top + 1
                                       .Width = C.Width - 2     'vorm aanpassen
                                       .Height = C.Height - 2
                                       .Name = "SHP_"
                                  End With
                             End If
                        End If
                Next
          
Case Else

'Get date ranges
    Set DtRng = Range(Cells(r, LftCell), Cells(r, RtCell))
        LftCell = Cells(r, 5) + 1 - Cells(6, 5) + 8
        RtCell = Cells(r, 6) + 1 - Cells(r, 5) + 12
        
    'if "fase" in C then add a rectangle
    If Cells(r, 3) = "Fase" Or Cells(r, 3) = "Project" Then
    Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, DtRng.Left + 2, DtRng.Top + 2, DtRng.Width - 10, DtRng.Height - 10)
          NewShp.Fill.ForeColor.RGB = fc
            NewShp.Line.ForeColor.RGB = fc 'FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
    Set DtRng = Range(Cells(r, LftCell), Cells(r, RtCell))
        LftCell = Cells(r, 5) + 1 - Cells(6, 5) + 17
        RtCell = Cells(r, 5) + 1 - Cells(r, 5) + 19
    Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeFlowchartMerge, Cells(r, LftCell).Left + 1, Cells(r, LftCell).Top + 2, Cells(r, LftCell).Width - 5, Cells(r, LftCell).Height - 4)
           NewShp.Fill.ForeColor.RGB = fc
            NewShp.Line.ForeColor.RGB = fc
    Set DtRng = Range(Cells(r, LftCell), Cells(r, RtCell))
        LftCell = Cells(r, 6) - Cells(6, 5) + 18
        RtCell = Cells(r, 5) + 1 - Cells(r, 5) + 19
    Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeFlowchartMerge, Cells(r, LftCell).Left + 4, Cells(r, LftCell).Top + 2, Cells(r, LftCell).Width - 5, Cells(r, LftCell).Height - 4)
           NewShp.Fill.ForeColor.RGB = fc
            NewShp.Line.ForeColor.RGB = fc
          
Else
            'Otherwise if text in C add arrow  bar
    Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeLeftRightArrow, DtRng.Left, DtRng.Top + 3, DtRng.Width, DtRng.Height - 6)
          NewShp.Fill.ForeColor.RGB = fc
            NewShp.Line.ForeColor.RGB = fc 'FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
          
    End If
End Select
'Name shape as per value
   NewShp.Name = ShpName

Sheets("Projectplanning").Protect Password:=Wachtwoord()
End Sub
 
deze dus

'Get date ranges
Set DtRng = Range(Cells(r, LftCell), Cells(r, RtCell))
LftCell = Cells(r, 5) + 1 - Cells(6, 5) + 8
RtCell = Cells(r, 6) + 1 - Cells(r, 5) + 12

Else
'Otherwise if text in C add arrow bar
Set NewShp = ActiveSheet.Shapes.AddShape(msoShapeLeftRightArrow, DtRng.Left, DtRng.Top + 3, DtRng.Width, DtRng.Height - 6)
NewShp.Fill.ForeColor.RGB = fc
NewShp.Line.ForeColor.RGB = fc 'FormulaLocal = "VERT.ZOEKEN(range(C12:C50);Blad3!E3:I28;5;onwaar)"
 
ik denk dat "placement" default die shape zo is, maar anders eens voor de test (idem voor NewShp)
CSS:
     With Dupl                               'die shape
          .Left = C.Left + 1                 'verplaatsen
          .Top = C.Top + 1
          .Width = C.Width - 2               'vorm aanpassen
          .Height = C.Height - 2
          .Name = "SHP_"
          .Placement = xlMoveAndSize   'ik denk dat dit eigenlijk default al zo is
     End With
 
Beste cow18,

Ik heb de code aangepast. bij mij werkt het nog steeds. a.s. maandag kan ik pas aan mij n collega vragen om dit te testen.
Voor nu al bedankt voor het meedenken.
 
Beste cow18,

Ik had alleen op een plaats de aanpassing gedaan. Als ik het ook bij NewShp doe krijg ik een foutmelding.
De toevoeging op deze plaats heeft echter geen effect.
 
Mijn excuses,
Onderstaande melding dus

---------------------------
Microsoft Visual Basic for Applications
---------------------------
Compileerfout:

Ongeldige of niet-gekwalificeerde verwijzing
---------------------------
OK Help
---------------------------
 
Dan heb je een foutje gemaakt bij het wijzigen van de code.
Kijk dat dus eens goed na.
 
Terug
Bovenaan Onderaan