code to check a checkbox if value of cell is "1"

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I know this is generally backwards from how its usually done (that is to say when a checkbox is checked the link to another cell the value changes to "1") but I need a macro that looks at a range of cells in a column; "O18:O386", which are all going to be either "1" or "0" , and if its a "1", then the checkbox beside it in column "N" is going to be checked (TRUE). If its "0", then not checked.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If the checkbox is linked to the cell, if you enter either true or 1 in the linked cell the checkbox should check/uncheck automatically.
 
Upvote 0
Understood, thank you. I should back up some and explain what the problem is:
The column beside the checkbox is hidden and is either a 1 or a 0 (linked to the checkbox beside it.)
The checkboxes are form control boxes.
I have 2 ways on the spreadsheet of sorting. commandbuttons for each field (column), and comboboxes for 4 fields (you remeber, you helped me get them working lol
icon14.png
)
WHenever the combobox is used, and then after I either hit the 'reset' button (which unsorts all) of select another sort command button is selected, the boxes are all alittle off inside the cell (row) which they reside in (all the rows are the same height and remain the same height)
So i found a macro that recenters all the boxes back to there original position centered in their cell. I just put that little bit of code at the end of each command that sorts/filters the data.... and that worked.
But, for whatever reason, it also removes the check inside the box... even though the "1" or "0" in the cell adjacent to it is still correct (but now that box doesnt have a check, even though the linked cell is still a 1(??) )
So I was thinking that if I insert ANOTHER code to check if the column is a "1", and if it is, then apply a check to the box beside it.
(this is all confusing, but it really isnt... just going to post some screenshots to help illustrate what its doing...)
 
Upvote 0
Ok, so here it is with the hidden column "O" un-hidden so you can see what the linked cell is for each checkbox:

14v480i.jpg


So after running a sort/filter it looks like this: The data is still correct (the "1" 's are still in the right cells) but some of the boxes have now become unchecked.

2ic9tvs.jpg


some of the boxes are really off-center from their cell, as you can see: (this also shows the macro right before i run it manually)

30lffp5.jpg



continued in next reply...
 
Upvote 0
Here it is again but after the "aligning" macro is ran: (recentered all boxes, but now missing a check for many of the boxes. )
icon8.png


vh9f6r.jpg
 
Upvote 0
crap... sorry for making these so big... thought I had them resized smaller than this. :(
 
Upvote 0
What happens if you run this
Code:
Range("O:O").Replace 1, 1, xlWhole, , , , False, False
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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