Skip i'r prif gynnwys

Sut i blwch gwirio auto-ganolfan yn y gell yn Excel?

Wrth fewnosod blychau gwirio mewn celloedd yn Excel, efallai y byddwch yn sylwi ei bod yn anodd trefnu pob blwch gwirio yn drefnus fel y dangosir y screenshot chwith. A dweud y gwir, gallwch chi symud pob blwch gwirio i ganolfan y celloedd i'w cadw mewn trefn daclus. Gall dull yn yr erthygl hon eich helpu chi.

Blwch gwirio awto-ganolfan yn y gell gyda chod VBA


Blwch gwirio awto-ganolfan yn y gell gyda chod VBA

I ganoli pob blwch gwirio mewn celloedd yn awtomatig mewn taflen waith gyfredol, gwnewch fel a ganlyn.

1. Yn y daflen waith, mae angen i chi ganoli'r holl flychau gwirio yn awtomatig, pwyswch y Alt + F11 allweddi i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch Mewnosod > Modiwlau. Yna copïwch a gludwch god VBA i mewn i'r ffenestr cod.

Cod VBA: Canoli pob blwch gwirio mewn celloedd yn awtomatig

Sub CenterCheckbox ()
    Dim xRg As Range
    Dim chkBox As OLEObject
    Dim chkFBox As CheckBox
    On Error Resume Next
    Application.ScreenUpdating = False
    For Each chkBox In ActiveSheet.OLEObjects
        If TypeName(chkBox.Object) = "CheckBox" Then
            Set xRg = chkBox.TopLeftCell
            chkBox.Width = xRg.Width * 2 / 3
            chkBox.Height = xRg.Height
            chkBox.Left = xRg.Left + (xRg.Width - chkBox.Width) / 2
            chkBox.Top = xRg.Top + (xRg.Height - chkBox.Height) / 2
        End If
    Next
    For Each chkFBox In ActiveSheet.CheckBoxes
        Set xRg = chkFBox.TopLeftCell
        chkFBox.Width = xRg.Width * 2 / 3
        chkFBox.Height = xRg.Height
        chkFBox.Left = xRg.Left + (xRg.Width - chkFBox.Width) / 2
        chkFBox.Top = xRg.Top + (xRg.Height - chkFBox.Height) / 2
    Next
    Application.ScreenUpdating = True
End Sub

3. Gwasgwch y F5 allwedd. Yna mae'r holl flychau gwirio yn cael eu symud i ganol y celloedd ar unwaith fel y dangosir isod y screenshot.

Nodyn: Gellir cymhwyso'r cod VBA hwn i CheckBox (ActiveX Control) a CheckBox (Rheoli Ffurflen).

Tip: Os ydych chi am fewnosod blychau gwirio lluosog mewn ystod ddethol mewn swmp, gallwch roi cynnig ar y Mewnosod Swp Blychau Gwirio pf cyfleustodau Kutools ar gyfer Excel. Neu swp mewnosodwch Botymau Opsiwn lluosog gyda'r Mewnosod Swp Botymau Opsiwn cyfleustodau. Ar ben hynny, gallwch chi ddileu'r holl flychau gwirio ar unwaith gyda'r Blychau Gwirio Swp Dileu dangosir cyfleustodau fel isod sgrinluniau. Gallwch chi fynd i lawrlwythwch y feddalwedd am ddim heb unrhyw gyfyngiad mewn 30 diwrnod.


Erthyglau cysylltiedig:

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
Comments (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
The VBA does not work at all for me. When I press F5, it appears that the module runs, but the checkboxes did not move.
This comment was minimized by the moderator on the site
After some more experimenting, I figured out that the VBA does work for manually inserted checkboxes, but if I use Kutools batch insert, it does not. How do I center all the checkboxes inserted with Kutools?
This comment was minimized by the moderator on the site
Hi quadma,
The code also works for the checkboxes inserted by Kutools. Which Excel version are you using?
This comment was minimized by the moderator on the site
I'm using office 360. I think the issue that I'm having is that when I use the Kutools batch insert, the size of the the checkbox object is as wide as the column that it's inserted into (i.e. the checkbox object width is greater than it's height), with the visible checkbox itself on being left justified within the object. If I select all the checkbox objects and then resize them so that the height and length are equal, and then run the VBA, it does then center the checkboxes within the column.





This seems like an unnecessary step, given that checkboxes are square, why is Kultools not making the checkbox objects square?
This comment was minimized by the moderator on the site
Hi quadma,
The check boxes inserted by Kutools are the same as the Check Box (Form Control) which inserted by Excel.
I don't really understand you said "making the checkbox object square". Normally a check box include the box field and the value field. Kutools keeps the check boxes' value empty if the selected cells are blank. And if there are values in selected cells, the cell value will be taken as the check box value.
This comment was minimized by the moderator on the site
I've uploaded a picture to show what I mean. Hopefully that helps.
This comment was minimized by the moderator on the site
Hi quadma, I got your point. We will think about it and thank you for your patience.
This comment was minimized by the moderator on the site
This worked great for me except it doesn't align it with the text in the next cell which is bottom aligned. Is there a way to align the checkboxes for bottom aligned in order to get them to align with the text in the next cell? Thanks!
This comment was minimized by the moderator on the site
You VDA script is partly working. Because when i applied it, linked cell next to Checkbox get changed and got linked with a cell under it.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations