Check box problem

jrussellCW

New Member
Joined
Aug 12, 2011
Messages
8
Hi there, new to the forum, I have a quick easy question. I am trying to create a macro, using vb, that will add a check box to the cell I have selected, label the check box "Produced" and link the checkbox to the cell 2 cells to the right.
It should also then create a check box in the cell to the right of "produced", and label this new check box "Received" This new check box will be linked to the cell two cells to its right.
The result will be two check-boxes in adjacent cells, returning "true" and "false" to the next two cells over.
Then I will have Two cells that sum up the number of "true's" for each column, So that I can easily see how many commercials each month production has produced, and how many they have received. I thought it would be simple, but it's giving me trouble.
oh, and the check boxes must be limited in size to the size of the cell they are in, there are going to be lots of them down the column.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
The counter is working fine, by the way, but it just takes forever to manually set up each check box. The macro would make this much easier
 
Upvote 0
Here's something you might try.
Works well for me here but I guess it'll depend on your sheet layout as to how much tweaking it needs. (Uses checkboxes from the Forms toolbar.)
Code:
Sub InsertChkBx()
    
ActiveSheet.CheckBoxes.Add(0, 0, 0, 0).Select
With Selection
  .Characters.Text = "Produced"
  .ShapeRange.LockAspectRatio = msoFalse
  .ShapeRange.Height = ActiveCell.Height
  .ShapeRange.Width = ActiveCell.Width
  .ShapeRange.IncrementLeft ActiveCell.Left
  .ShapeRange.IncrementTop ActiveCell.Top
  .Value = xlOn
  .LinkedCell = ActiveCell(, 3).Address
End With
    
ActiveSheet.CheckBoxes.Add(0, 0, 0, 0).Select
With Selection
  .Characters.Text = "Received"
  .ShapeRange.LockAspectRatio = msoFalse
  .ShapeRange.Height = ActiveCell.Height
  .ShapeRange.Width = ActiveCell(, 2).Width
  .ShapeRange.IncrementLeft ActiveCell(, 2).Left
  .ShapeRange.IncrementTop ActiveCell(, 2).Top
  .Value = xlOn
  .LinkedCell = ActiveCell(, 4).Address
  .Value = xlOff
End With
    
Application.SendKeys "{ESC}"
End Sub
Does that get you any closer?
 
Last edited:
Upvote 0
With a twist:
Code:
Sub CreateCheckBoxes()
    Dim curCell As Range, r As Long, x As Long
    r = Application.InputBox("How many rows?", "", 1, , , , , 1) - 1
    For x = ActiveCell.Row To ActiveCell.Row + r
      Set curCell = ActiveCell
      ActiveSheet.CheckBoxes.Add(curCell.Left, curCell.Top, curCell.Width, curCell.Height).Select
      With Selection
        .Characters.Text = "Produced"
        .LinkedCell = curCell.Offset(, 2).Address
        .Value = xlOn
        .Value = xlOff
      End With
      Set curCell = curCell.Offset(, 1)
      ActiveSheet.CheckBoxes.Add(curCell.Left, curCell.Top, curCell.Width, curCell.Height).Select
      With Selection
        .Characters.Text = "Received"
        .LinkedCell = curCell.Offset(, 2).Address
        .Value = xlOn
        .Value = xlOff
      End With
      ActiveCell.Offset(1).Select
    Next x
End Sub
 
Upvote 0
That did it, awesome thanks! Only thing I would change is that the first check box seems to be checked by default. Not a big deal. Thanks very much!
 
Upvote 0
With a twist:
Code:
Sub CreateCheckBoxes()
    Dim curCell As Range, r As Long, x As Long
    r = Application.InputBox("How many rows?", "", 1, , , , , 1) - 1
    For x = ActiveCell.Row To ActiveCell.Row + r
      Set curCell = ActiveCell
      ActiveSheet.CheckBoxes.Add(curCell.Left, curCell.Top, curCell.Width, curCell.Height).Select
      With Selection
        .Characters.Text = "Produced"
        .LinkedCell = curCell.Offset(, 2).Address
        .Value = xlOn
        .Value = xlOff
      End With
      Set curCell = curCell.Offset(, 1)
      ActiveSheet.CheckBoxes.Add(curCell.Left, curCell.Top, curCell.Width, curCell.Height).Select
      With Selection
        .Characters.Text = "Received"
        .LinkedCell = curCell.Offset(, 2).Address
        .Value = xlOn
        .Value = xlOff
      End With
      ActiveCell.Offset(1).Select
    Next x
End Sub
Ooh I like this one better. That will allow me to create as many as I need. Thanks! I should have kept up my visual basic. The last thing I ever did with it was years ago, i programmed a mancala game. It was awesome.
 
Upvote 0
I should make an excel mancala, that would be interesting.

Is there a way to make excel highlight rows if neither check box is checked?
 
Upvote 0
I'm sure.

Does it need to be interactive?

By that I mean:
Start off with both False and row is highlighted,
Then one is True and highlight off
If set back to both False highlight again?
 
Upvote 0

Forum statistics

Threads
1,215,201
Messages
6,123,617
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top