Sub Camera(Rij)
Dim Rij_B, Rij_A1, Rij_A2, sHoofdstuk, shA, shB, Cam, cB
Set shB = Sheets("Begroting")
Set shA = Sheets("Aanbieding")
Set Cam = Sheets("Begroting").Shapes("Camera1")
'**** KLIK JE IN BEGROTING OP EEN ANDER HOOFDSTUK ???? *******************
With shB.UsedRange.Columns(3)
If Rij < 10 Or Rij >= .Row + .Rows.Count + 5 Then MsgBox "buiten bereik": GoTo fout
End With
Rij_B = Evaluate(Replace("=AGGREGATE(14,6,ROW(Begroting_§)/((LEFT(Begroting_§,1)=""§"")*(ROW(Begroting_§)<=#)),1)", "#", Rij)) 'rij waar het hoofdstuk staat
If Rij_B = Rij_Begroting Then Exit Sub 'identiek aan vorige keer = stoppen
'****** MET WELK HOOFDSTUK IN AANBIEDING STEMT DIT OVEREEN *************
Rij_Begroting = Rij_B
Set cB = shB.Cells(Rij_B, "AD") 'cel waar straks de camera wordt gezet
sHoofdstuk = shB.Cells(Rij_B, "C").Value 'huidig hoofdstuk
Rij_A1 = Application.Match(sHoofdstuk, shA.Columns("B"), 0) 'startrij in Aanbieding
If Not IsNumeric(Rij_A1) Then MsgBox "Hoofdstuk niet gevonden", vbInformation, sHoofdstuk: GoTo fout
Rij_A2 = shA.Cells(Rij_A1, "B").End(xlDown).Row - Rij_A1
If Rij_A2 > 20 Then MsgBox "teveel regels voor dat hoofdstuk", vbInformation, sHoofdstuk: GoTo fout
shA.Cells(Rij_A1, 1).Resize(Rij_A2, 12).Name = "Bereik" 'benoemd bereik "bereik" = je camerastandpunt
'********* PAS DE CAMERA AAN ****************************************
With Cam
.Visible = True
.Top = cB.Top '
.Left = cB.Left
.ScaleHeight 1.2, msoTrue, msoScaleFromTopLeft 'zowel hoogte als breedte een ratio van 1.2 tov origineel (zelf aan te passen)
.ScaleHeight 1.2, msoTrue, msoScaleFromTopLeft
Application.ScreenUpdating = True
End With
Exit Sub
fout:
Cam.Visible = False
Application.ScreenUpdating = True
End Sub