Results 1 to 5 of 5

VBA to add Checkboxes Based on Condition in Another Range

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2013
    Posts
    197

    VBA to add Checkboxes Based on Condition in Another Range

    I'm needing to add a condition to the following code, but I just can't get the syntax right. I need it to insert checkboxes into column F only when there is data in Column A.

    The code in bold is my attempt to add the condition. What am I doing wrong?



    
    Option Explicit
    Sub InsertCheckboxes()
    
     
    Sub Test()
    
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 8).End(xlUp).Row
    
    Dim myBox As CheckBox
    Dim myCell As Range
    
    Dim Last As Long
    Dim i As Integer
    Dim cellRange As Range
    Dim cboxLabel As String
    Dim linkedColumn As String
    
        Set cellRange = Range("F4:F" & LastRow & "")
    
        linkedColumn = "Z"
    
        cboxLabel = ""
    
        With ActiveSheet
            For Each myCell In cellRange
    
            For i = Last To 1 Step -1
                If (Cells(i, "A").Value) <> "" Then
    
                    With myCell
                        Set myBox = .Parent.CheckBoxes.Add(Top:=.Top, _
                                                           Width:=.Width, Left:=.Left, Height:=.Height)
        
                        With myBox
                            .LinkedCell = linkedColumn & myCell.Row
                            .Caption = cboxLabel
                            .Name = "checkbox_" & myCell.Address(0, 0)
                            .OnAction = "Mixed_State"
                        End With
        
                        .NumberFormat = ";;;"
                    
                    End With
                End If
            Next i
            
            Next myCell
        End With
    
    
    End Sub

    thanks!!
    Last edited by phelbin; 07-29-2016 at 06:54 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How to sum range based on condition
    By JackBauer in forum Excel General
    Replies: 4
    Last Post: 01-28-2016, 09:45 AM
  2. How would you set up a dynamic range based on this condition
    By unnobtanium in forum Excel General
    Replies: 17
    Last Post: 12-11-2014, 01:15 PM
  3. Checkboxes If Else condition..
    By siobeh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-24-2014, 05:11 PM
  4. Highlighting a range from A:I based on condition
    By naga in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2014, 04:46 AM
  5. Set Checkboxes to Checked/Unchecked in Range based on Values in Other Range
    By lowprofile in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2013, 11:25 AM
  6. Print Sheets based on checkboxes in UserForm, Checkboxes also control another macro
    By krackaberr in forum Excel Programming / VBA / Macros
    Replies: 34
    Last Post: 03-05-2013, 11:12 AM
  7. Replies: 3
    Last Post: 08-11-2012, 09:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1