zondag, 02 november 2014 12:59

Gemakkelijk checkboxen aanmaken Speciaal

Geschreven door
Beoordeel dit item
(2 stemmen)

De volgende macro heb ik geschreven n.a.v. een vraag van iemand of het mogelijk was om snel per rij in Excel een aantal checkboxes aan te maken die allemaal koppelen naar de volgende kolom. Dus bijvoorbeeld in kolom D vanaf rij 5 20 checkboxes die linken naar kolom rij 5 t/m 25.

 Sub SnelAanmakenCheckBoxen()
    Dim str1 As String
    Dim str2 As String
    Dim str3 As String
    Dim str4 As String
    Dim OLEObj As OLEObject
    Application.ScreenUpdating = False
    
    
    str1 = InputBox("Geef een unieke naam ter identificatie van de checkboxen (b.v. verdediger,middenvelder,aanvaller):", "Naam")
    str2 = InputBox("In welke kolom moeten de checkboxen komen (D,E,F,etc):", "Kolom info")
    str3 = InputBox("Start checkboxen op rij (1,2,3,etc):", "Startrij")
    str4 = InputBox("Stop checkboxen op rij (1,2,3,etc):", "Stoprij")
    
    Dim i
    Dim nleft As Integer
    Dim ntop As Integer
    Dim nname As String
    
    If Val(str3) = 0 Or Val(str4) = 0 Then
        MsgBox ("Geen geldige rij opgegeven voor checkboxen")
        Exit Sub
    End If
        '
    For i = Val(str3) To Val(str4) 'cells from 1st to 10th
    
    nleft = Cells(i, str2).Left
    ntop = Cells(i, str2).Top
    
    
    Set OLEObj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _
        DisplayAsIcon:=False, Left:=nleft, Top:=ntop, Width:=21.75, Height:=15 _
        )
        
     nname = str1 & i
        
     OLEObj.Name = nname
     OLEObj.Object.Caption = ""
     OLEObj.LinkedCell = Chr(Asc(str2) + 1) & i
     OLEObj.Object.Value = False
    
    Application.ScreenUpdating = True
    Next
End Sub

 Met deze macro kon hij zijn Excel gemakkelijk opbouwen zonder stuk voor stuk de checkboxes aan te hoeven maken.

Klik HIER voor de Excel

Aanvullende informatie

  • Versies: Alle versies
Lees 6951 keer Laatst aangepast op zondag, 02 november 2014 19:49
Log in om reacties te plaatsen

Excel Software Shop

Web Analytics