Gå til hovedindhold

Hvordan låses eller fryses regnearkfanen i Excel?

Antager du at du har en projektmappe, der indeholder flere regneark, er der et regneark, der hedder Hovedark som den første fane i projektmappen. Og nu vil du prøve at låse eller fryse denne arkfane for at gøre den altid synlig, selv når du ruller over et antal regneark. Faktisk er der ingen direkte måde, hvorpå du fryser fanen, men du kan bruge en løsning til at løse dette problem.

Lås eller frys en bestemt regnearkfane med VBA-kode


pil blå højre boble Lås eller frys en bestemt regnearkfane med VBA-kode

I Excel kan vi anvende følgende VBA-kode for at gøre det specifikke regneark altid før din nuværende klikede regnearkfane, så du altid kan se dette regneark, når du ruller på tværs af andre arkfaner. Gør følgende:

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

2. Vælg derefter ThisWorkbook fra venstre Projekt Explorer dobbeltklik på den for at åbne Moduler, og kopier og indsæt derefter følgende VBA-kode i det tomme modul:

VBA-kode: Frys eller lås en bestemt fane på regnearket

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'Update by Extendoffice
Application.EnableEvents = False
Application.ScreenUpdating = False
If Application.ActiveSheet.Index <> Application.Sheets("Main-sheet").Index Then
    Application.Sheets("Main-sheet").Move Before:=Application.Sheets(Application.ActiveSheet.Index)
    Application.Sheets("Main-sheet").Activate
    Sh.Activate
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

doc-fryse-ark-fane-1

3. Og gem derefter og luk denne kode, nu når du klikker på en af ​​dine regnearksfaner, vil dette specifikke regneark altid være forrest på din klikede arkfane, se skærmbilleder:

doc-fryse-ark-fane-2
-1
doc-fryse-ark-fane-3

Bemærk: I ovenstående kode er hovedarket det arknavn, du vil fryse, du kan ændre det til dit behov.


Relaterede artikler:

Sådan fryses ruder i Excel 2010?

Hvordan påføres fryse / fryse ruder på flere regneark på én gang?

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 (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
chăng đc gi cả
This comment was minimized by the moderator on the site
As Thuyen pointed out 2 years ago, you can't copy data between sheets while this code is active. Furthermore, the code is needlessly complicated. The sheet that you activate is passed to the procedure as the parameter "Sh". This makes the frequent calls to "ActiveSheet" unnecessary, and could cause problems for someone who's trying to modify the code but isn't very experienced.

Here's my versions that corrects those issues, and even shows how to add a 2nd "Main" sheet (similar to what Dzingai posted):
-----------------------------------------------------------------

'These 2 lines aren't necessary if you use the sheets' codenames, which I recommend.
Set shtMain1 = Worksheets("Main-Sheet-1")
Set shtMain2 = Worksheets("Main-Sheet-2")

If Application.CutCopyMode = False Then
If Sh.Index <> shtMain1.Index And Sh.Index <> shtMain2.Index Then
shtMain1.Move before:=Sh
shtMain2.Move before:=Sh
Sh.Activate
End If
End If
This comment was minimized by the moderator on the site
This code worked well. Only problem is...if we close the file & open it again it goes off.
This comment was minimized by the moderator on the site
[quote]This code worked well. Only problem is...if we close the file & open it again it goes off.By Sangs[/quote] Try saving document as Macro-Enabled Workbook. I think it should work well that way.
This comment was minimized by the moderator on the site
Is it possible to create one with multiple arguments? Like instead of just moving the one main sheet to the front of where you are working, is it possible to move three tabs in front of what you are working on?
This comment was minimized by the moderator on the site
Yes, it is possible, you just have to add more arguments to the if clause using the "AND" like this IF Application.ActiveSheet.Index Application.Sheets("Main-sheet").Index AND Application.ActiveSheet.Index Application.Sheets("Other-Main-sheet").Index and so on... Then Application.Sheets("Main-sheet").Move Before:=Application.Sheets(Application.Sheets("Other-Main-sheet").Index) Application.Sheets("Main-sheet").Activate Application.Sheets("Other-Main-sheet").Move Before:=Application.Sheets(Application.ActiveSheet.Index) Application.Sheets("Other-Main-sheet").Activate Sh.Activate This will place the Main-Sheet, then the Other-Main-Sheet in front of your active sheet.
This comment was minimized by the moderator on the site
is this vba my excel sheet not freezeplease give me solution
This comment was minimized by the moderator on the site
Could not get your code to work, but this one did :) Private Sub Workbook_SheetActivate(ByVal Sh As Object) Dim sc As Long ' count of sheets Dim NewPos As Long ' index of serlected sheet Application.EnableEvents = False Application.ScreenUpdating = False If ActiveSheet.Index 1 Then sc = Sheets.Count NewPos = ActiveSheet.Index For i = 2 To NewPos - 1 Sheets(2).Move After:=Sheets(sc) Next i Sheets(1).Activate Sheets(2).Activate End If Application.ScreenUpdating = True Application.EnableEvents = True End Sub
This comment was minimized by the moderator on the site
When I use VBA, I cannot copy data from Main-Sheet to another sheet Please help me fix this bug
This comment was minimized by the moderator on the site
hahaha. so true! did you find a fix for this?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations