Gå til hovedindhold

Hvordan grupperes og opdeles rækker i beskyttet regneark?

Som vi alle vidste, er der i et beskyttet regneark mange begrænsninger for os at anvende nogle operationer. Såsom, vi kan ikke skifte mellem grupperede og ikke-grupperede data. Er der en måde at gruppere eller ophæve gruppering af rækker på et beskyttet regneark?

Gruppér og opdel rækker i et beskyttet regneark med VBA-kode


pil blå højre boble Gruppér og opdel rækker i et beskyttet regneark med VBA-kode

Måske er der ingen anden god måde at løse dette problem på, men ved hjælp af en VBA-kode skal du gøre som følger:

1. Aktivér dit regneark, som du vil bruge, skal du sørge for, at regnearket ikke er beskyttet endnu.

2. Hold derefter nede ALT + F11 tasterne, og det åbner Vinduet Microsoft Visual Basic til applikationer.

3. Klik indsatte > Moduler, og indsæt følgende kode i Modul vindue.

VBA-kode: Gruppér og opdel rækker i et beskyttet regneark

Sub EnableOutlining()
'Update 20140603
Dim xWs As Worksheet
Set xWs = Application.ActiveSheet
Dim xPws As String
xPws = Application.InputBox("Password:", xTitleId, "", Type:=2)
xWs.Protect Password:=xPws, Userinterfaceonly:=True
xWs.EnableOutlining = True
End Sub

4. Tryk derefter på F5 nøgle til at køre denne kode, og der vises et promptfelt for at minde dig om at indtaste adgangskoden for at beskytte det aktuelle regneark. Se skærmbillede:

doc-gruppe-i-beskyttet-ark1

5. Klik derefter på OK, dit regneark er blevet beskyttet, men du kan udvide og trække kontursymbolerne i dette beskyttede regneark, se skærmbillede:

doc-gruppe-i-beskyttet-ark1

Bemærk: Hvis dit regneark allerede er beskyttet, fungerer denne kode ikke.

Bedste kontorproduktivitetsværktøjer

🤖 Kutools AI Aide: Revolutionér dataanalyse baseret på: Intelligent udførelse   |  Generer kode  |  Opret brugerdefinerede formler  |  Analyser data og generer diagrammer  |  Aktiver Kutools funktioner...
Populære funktioner: Find, fremhæv eller identificer dubletter   |  Slet tomme rækker   |  Kombiner kolonner eller celler uden at miste data   |   Runde uden formel ...
Super opslag: VLookup med flere kriterier    Multiple Value VLookup  |   VOpslag på tværs af flere ark   |   Fuzzy Lookup ....
Avanceret rulleliste: Opret hurtigt rulleliste   |  Afhængig rulleliste   |  Multivælg rulleliste ....
Column Manager: Tilføj et bestemt antal kolonner  |  Flyt kolonner  |  Skift synlighedsstatus for skjulte kolonner  |  Sammenlign områder og kolonner ...
Fremhævede funktioner: Grid fokus   |  Designvisning   |   Stor Formel Bar    Arbejdsbog & Ark Manager   |  Ressourcebibliotek (Autotekst)   |  Datovælger   |  Kombiner regneark   |  Krypter/Dekrypter celler    Send e-mails efter liste   |  Superfilter   |   Specielt filter (filter fed/kursiv/gennemstreget...) ...
Top 15 værktøjssæt12 tekst Værktøjer (tilføje tekst, Fjern tegn, ...)   |   50 + Chart Typer (Gantt kort, ...)   |   40+ Praktisk formler (Beregn alder baseret på fødselsdag, ...)   |   19 Indsættelse Værktøjer (Indsæt QR-kode, Indsæt billede fra sti, ...)   |   12 Konvertering Værktøjer (Tal til ord, Valutaomregning, ...)   |   7 Flet og del Værktøjer (Avancerede kombinere rækker, Opdel celler, ...)   |   ... og mere

Overlad dine Excel-færdigheder med Kutools til Excel, og oplev effektivitet som aldrig før. Kutools til Excel tilbyder over 300 avancerede funktioner for at øge produktiviteten og spare tid.  Klik her for at få den funktion, du har mest brug for...

Beskrivelse


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!
Comments (33)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Fantástico, me resolveu rápido um grande problema, sua explicação é perfeita, didática, direta sem erros nem enrolação, parabéns. Obrigado!
This comment was minimized by the moderator on the site
Hello,
Thanks for these explanations, it works well.
I have a file with 3 outline symbols.
I would like to enable the user to group and ungroup rows when clicking on the symbols 1 and 2,but to prevent him from ungrouping rows when clicking on the symbol 3.
Is there any way to achieve this ?
Thanks in advance
This comment was minimized by the moderator on the site
这样筛选功能不能用啊
This comment was minimized by the moderator on the site
Is there a way to get this to work on a shared workbook? - I need the track changes, Thanks
This comment was minimized by the moderator on the site
f*ck, this stole my excel later and changed password privately
This comment was minimized by the moderator on the site
How To Group And Ungroup Rows and Columns In Protected Worksheet?
This comment was minimized by the moderator on the site
formidable
This comment was minimized by the moderator on the site
Someone might need this, I think I figured out how to make this work.

First, your code needs to be written in "ThisWorkbook" under Microsoft Excel Objects, as @peachyclean suggests.
Second, take the code that @Sravanthi wrote, and paste to the above mentioned location.

Sub Workbook_Open()
'Update 20140603
Dim xWs As Worksheet
Set xWs = Application.ActiveSheet
Dim xPws As String
xPws = "rfc" ''Application.InputBox("Password:", xTitleId, "", Type:=2)
xWs.Protect Password:=xPws, Userinterfaceonly:=True
xWs.EnableOutlining = True
End Sub

The thing is that you need to be on the sheet which you want to protect but allowing using grouping, and save the workbook and close, without protecting. Now if you open it, the macro starts automatically, it will make the sheet protected with the password "rfc". Now you can use the grouping, the sheet is protected.

For my solution, I've modified the password applied, so you can rewrite any password HERE:
xPws = "WRITEANYPASSWORDHERE" ''Application.InputBox("Password:", xTitleId, "", Type:=2)

Furthermore, I didn't want the to-be-protected sheet active when opening the file, therefore I've modified this part:
Set xWs = Application.ActiveSheet ->
Set xWs = Application.Worksheets("WRITEANYSHEET'SNAMEHERE")

Now it works like charm, sheet named 'WRITEANYSHEET'SNAMEHERE' is protected but the grouping applicable. On the long run, I think the problem will be that if I want to modify this file and keep the solution, I need to unprotect this sheet to make it work on the next opening. I guess you can write another macro to automatically unprotect when closing :)


I hope it helped.
This comment was minimized by the moderator on the site
This string looked to be exactly what I needed, as I know nothing about VBA. I was able to get this to work initially but as was pointed out, once you close the spreadsheet and reopen it, it no longer works. I tried to write the code in "ThisWorkbook" as noted but I can't figure out how to do that. I can see "ThisWorkbook" but I don't know how to write in it. Every way I see to create a module, it creates a new module in a the separate "Modules" folder, outside of the "Microsoft Excel Objects" folder. Any suggestions on how to put this code in "ThisWorkbook" ?
This comment was minimized by the moderator on the site
Hii.. this worked wonders. the only place where i am getting stuck now is that i need to do this for multiple sheets in the workbook. can u pls help with that.
This comment was minimized by the moderator on the site
do you have visuals for the VBA Code discussed 6 days ago to peachyclean about ThisWorkbook under Microsoft Objects instead of a new module. The functionality is lost when I go back into my workbook
This comment was minimized by the moderator on the site
To fix the issue of this not working in your file after you've closed it and opened it again, you have to paste the VBA code in "ThisWorkbook" under Microsoft Excel Objects instead of a new module. This will then automatically run the macro every time the file is opened.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations