Note: The other languages of the website are Google-translated. Back to English
Log på  \/ 
x
or
x
Tilmeld  \/ 
x

or

Hvordan bruger jeg afkrydsningsfeltet til at skjule / fjerne rækker eller kolonner i Excel?

Antag, at du skal bruge et afkrydsningsfelt til at skjule eller skjule visse rækker eller kolonner. For eksempel, når afkrydsningsfeltet Active X Control er markeret, vises de bestemte rækker eller kolonner, ellers skjules de. Denne artikel viser dig metoden til, hvordan du bruger afkrydsningsfeltet til at skjule / skjule rækker eller kolonner i Excel med detaljer.

Brug afkrydsningsfeltet til at skjule / fjerne rækker eller kolonner med VBA-kode


Brug afkrydsningsfeltet til at skjule / fjerne rækker eller kolonner med VBA-kode

Følgende VBA-kode kan hjælpe dig med at skjule / fjerne visse rækker eller kolonner med afkrydsningsfeltet.

1. Når du har indsat et afkrydsningsfelt for Active X Control til regnearket, skal du højreklikke på afkrydsningsfeltet og derefter vælge Vis kode fra højreklikmenuen. Se skærmbillede:

2. i Microsoft Visual Basic til applikationer vindue, kopier og indsæt følgende VBA-kode i vinduet Kode.

VBA-kode: Brug afkrydsningsfeltet til at skjule / fjerne rækker eller kolonner

Private Sub CheckBox1_Click()
    [C:D].EntireColumn.Hidden = Not CheckBox1
End Sub

Noter:

1. I VBA-koden [C: D]. Hele kolonnen betyder, at kolonnen C og D skjules eller skjules ved at markere eller fjerne markeringen i det tilsvarende afkrydsningsfelt.

2. For at skjule eller vise visse rækker såsom række 6: 9, skal du ændre [C: D]. Hele kolonnen til [6: 9]. EntireRow i VBA-koden.

3. Tryk på andre + Q taster samtidigt for at lukke Microsoft Visual Basic til applikationer vindue.

4. Sluk nu for Design Mode under Udvikler fane som vist nedenstående skærmbillede:

Fra nu af, når afkrydsningsfeltet er markeret, vises de angivne rækker eller kolonner. Når det ikke er markeret, skjules de angivne rækker eller kolonner.


Relaterede artikler:


De bedste Office-produktivitetsværktøjer

Kutools til Excel løser de fleste af dine problemer og øger din produktivitet med 80%

  • Genbruge: Indsæt hurtigt komplekse formler, diagrammer og alt, hvad du har brugt før; Krypter celler med adgangskode Opret postliste og send e-mails ...
  • Super formel bar (let redigere flere linjer med tekst og formel); Læsning Layout (let at læse og redigere et stort antal celler); Indsæt til filtreret rækkevidde...
  • Flet celler / rækker / kolonner uden at miste data; Split celler indhold; Kombiner duplikerede rækker / kolonner... Forhindre duplikerede celler; Sammenlign områder...
  • Vælg Duplicate eller Unique Rækker; Vælg tomme rækker (alle celler er tomme); Super Find og Fuzzy Find i mange arbejdsbøger; Tilfældig valg ...
  • Præcis kopi Flere celler uden at ændre formelreference; Auto Opret referencer til flere ark; Indsæt kugler, Afkrydsningsfelter og mere ...
  • Uddrag tekst, Tilføj tekst, Fjern efter position, Fjern mellemrum; Opret og udskriv personsøgningssubtotaler; Konverter mellem celler indhold og kommentarer...
  • Superfilter (gem og anvend filterskemaer på andre ark); Avanceret sortering efter måned / uge / dag, hyppighed og mere; Specielt filter af fed, kursiv ...
  • Kombiner arbejdsbøger og arbejdsark; Fletabeller baseret på nøglekolonner; Opdel data i flere ark; Batch Konverter xls, xlsx og PDF...
  • Mere end 300 kraftfulde funktioner. Understøtter Office / Excel 2007-2019 og 365. Understøtter alle sprog. Nem implementering i din virksomhed eller organisation. Fuld funktioner 30-dages gratis prøveperiode. 60-dages pengene tilbage garanti.
kte-fane 201905

Fanen Office bringer en grænseflade til et kontor med Office, og gør dit arbejde meget lettere

  • Aktiver redigering og læsning af faner i Word, Excel, PowerPoint, Publisher, Access, Visio og Project.
  • Åbn og opret flere dokumenter i nye faner i det samme vindue snarere end i nye vinduer.
  • Øger din produktivitet med 50% og reducerer hundredvis af museklik for dig hver dag!
officetab bund
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    etb1025 · 4 months ago
    What if i wanted to use 3 different checkboxes and wanted them to each toggle hiding different groups of rows? I have tried and looked all over. When I try to modify this code the checkboxes seem to interfere with each other.
  • To post as a guest, your comment is unpublished.
    Eric · 4 months ago
    What if i wanted to use 3 different checkboxes and wanted them to each toggle hiding different groups of rows? I have tried and looked all over. When I try to modify this code the checkboxes seem to interfere with each other.

  • To post as a guest, your comment is unpublished.
    Maggie · 1 years ago
    Very useful, but how can I use it to hide just a part of the spreadsheet? I mean for example cells B2:B11, how to combine those two functions? Thanks.
  • To post as a guest, your comment is unpublished.
    angela · 1 years ago
    It worked, but then when I saved the file, and reopen it doesn't work. I tried saving it as a Macro excel sheet and as a regular workbook. What have I done wrong? I want to give it to someone else to use and don't want them to be confused.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi angela,
      After adding the code into workbook, please click File > Save as, choose where to save the file, in the Save As dialog box, choose Excel Macro-Enabled Workbook (*.xlsm) from the Save as type drop-down, and finally click Save. Then send this Excel Macro-Enabled workbook to others.
  • To post as a guest, your comment is unpublished.
    May · 1 years ago
    I was try to unhide the first three role but it was not work.How can I do it ,I know it the person who send me that file wanna know my skill I can solve it or not.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi May,
      Sorry I didn't get your point.
  • To post as a guest, your comment is unpublished.
    Therese · 1 years ago
    Hello,

    Is there a way to hide only one row. If I put 6:9 all rows are hidden, but if I only put 6, it comes out as error. Would appreciate your help, thank you!
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi,
      Please change the second line in the code to:
      [6:6].EntireRow.Hidden = Not CheckBox1.
      Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Lou · 2 years ago
    Hi,

    Hi, I've done the code, it's work good but when I try to make the same in more than one checkbox at the same sheet they work 'together', only hide or unhide the rows if all three checkboxes are selected.
    I am tryint to make these three checkboxes works independent one from another. And let the users mark only one box for at time.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Lou,
      Please make sure the checkboxes you created are ActiveX Controls checkboxes. These checkboxes works independently in your worksheet.
      Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    Ed · 2 years ago
    Hello,

    I am trying to use this code to hide/unhide on a separate sheet from the checkbox. What do I have to add to make this work? Thanks in advance.

    Private Sub CheckBox1_Click()
    [C:D].EntireColumn.Hidden = Not CheckBox1
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good day,
      As the following code shown, please replace the "Sheet4" with your separate sheet name.

      Private Sub CheckBox1_Click()
      [Sheet4!C:D].EntireColumn.Hidden = Not CheckBox1
      End Sub
  • To post as a guest, your comment is unpublished.
    Cole · 3 years ago
    It seems like this code will only go one direction, i.e. only hide and not unhide them when clicked. Is there a way to correct this?
    • To post as a guest, your comment is unpublished.
      Kentthegreet · 2 years ago
      We have same problem but find a way to make it work. Please use ActiveX Controls checkbox and not at the Form Control checkbox. The code perfectly works with ActiveX checkbox.


      Private Sub CheckBox1_Click()
      [C:D].EntireColumn.Hidden = Not CheckBox1
      End Sub
    • To post as a guest, your comment is unpublished.
      Kentthegreet · 2 years ago
      We have same problem but I found out we're using Form Controls and not ActiveX Controls. The code perfectly works in ActiveX Control Checkbox button. Just turn off the Design Mode so you can click check the Checkbox.
  • To post as a guest, your comment is unpublished.
    Pieter Ramaut · 3 years ago
    @Wayne:

    Private Sub CheckBox1_Click()
    ActiveSheet.Unprotect Password:="xxxxx"
    Rows("284:351").EntireRow.Hidden = Not CheckBox1
    ActiveSheet.Protect Password:="xxxx"
    End Sub
  • To post as a guest, your comment is unpublished.
    Wayne Bailey · 4 years ago
    Is there a way to use the "Use checkbox to hide/unhide rows or columns with VBA code" on a protected worksheet?