Gå til hovedindhold

Hvordan ændres cellefarve, når der klikkes på eller vælges celle i Excel?

Forfatter: Siluvia Sidst ændret: 2020-07-30

Denne artikel viser dig nogle metoder til, hvordan du ændrer cellefarve, mens du klikker på en celle, og ændrer den fremhævede farve, mens du vælger et celleområde i Excel.

Skift cellefarve, når der klikkes på celle med VBA-kode
Skift den fremhævede farve, når celler er valgt med VBA-kode
Fremhæv hele rækken og kolonnen med aktiv celle med Kutools til Excel


Skift cellefarve, når der klikkes på celle med VBA-kode

Her kan du ændre baggrundsfarven på en celle, når du dobbeltklikker på den eller højreklikker på den med følgende VBA-kode.

1. I regnearket ændrer du cellefarven, når du klikker på den, højreklik på arkfanen og klik Vis kode fra højreklikmenuen.

2. i Microsoft Visual Basic til applikationer vindue, skal du kopiere og indsætte nedenstående VBA-kode i Kode vindue.

VBA: skift cellefarve, når du klikker på den

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.Color = vbRed
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.Color = vbGreen
End Sub

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

Derefter, når du dobbeltklikker på en celle, farves den i rødt. Og når du højreklikker på en celle, bliver den farvet i grønt. Se skærmbillede:


Et klik for at fremhæve række og kolonne i den valgte celle i Excel:

Kutools til Excel's Læsning Layout hjælpeprogram hjælper dig med hurtigt at fremhæve række og kolonne i den valgte celle i Excel som nedenstående demo vist.
Download og prøv det nu! (30-dages gratis spor)


Skift den fremhævede farve, når celler er valgt med VBA-kode

Som standard er den fremhævede farve grå, når du vælger et celleområde. Hvis du vil gøre det valgte interval mere markant, kan du ændre dets fremhævede farve til den, du har brug for. Gør som følger.

1. Højreklik på arkfanen, du vil ændre den fremhævede farve i det valgte område, og klik Vis kode fra højreklikmenuen.

2. i Microsoft Visual Basic til applikationer vindue, skal du kopiere og indsætte nedenstående VBA-kode i Kode vindue.

VBA-kode: skift den fremhævede farve i det valgte område

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target
        .Worksheet.Cells.FormatConditions.Delete
        .FormatConditions.Add xlExpression, , "TRUE"
        .FormatConditions(1).Interior.Color = vbYellow
    End With
End Sub

3. Trykke andre + Q taster på samme tid for at lukke Microsoft Visual Basic til applikationer vindue.

Fra nu af ændres den fremhævede farve i det valgte område eller celle til gul. Når du klikker på en anden celle eller et celleområde, farves cellerne automatisk.


Fremhæv hele rækken og kolonnen med aktiv celle med Kutools til Excel

Hvis du har et stort regneark at gøre, er det nødvendigt at fremhæve hele rækken og kolonnen i den aktive celle for at gøre læsning lettere. Her er Læsning Layout nytte af Kutools til Excel kan hjælpe dig.

Før påføring Kutools til Excel, Bedes download og installer det først.

1. klik Kutools > Læsning Layout. Se skærmbillede:

Derefter er læsningslayoutet aktiveret, du kan se rækken og kolonnen i den aktive celle fremhæves med det samme.

Bemærk: Du kan ændre indstillingerne for læsningslayout baseret på dine behov som vist nedenstående skærmbillede.

  Hvis du vil have en gratis prøveperiode (30 dage) af dette værktøj, klik for at downloade det, og gå derefter til at anvende handlingen i henhold til ovenstående trin.


Fremhæv hele rækken og kolonnen med aktiv celle med Kutools til Excel

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 (28)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, i built a dashboard with 37 worksheets, everyone with a table. All of them are lock panels because are to large and i need to know the number and name of the student who am i entering data for. Despite that, i have to keep my finger on the left side of the screen to identify the names and numbers to which the entered data refer.  So, i need to identify the first two cells of the row, in the columns "I" and "J".
The code that i took from the internet and couldn't change for the two cells of columns "I" and "J" was:

Dim lTarget As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Row >= 16 Then

If Not lTarget Is Nothing Then

lTarget.EntireRow.Interior.ColorIndex = 0
End If

Target.EntireRow.Interior.Color = 9359529

Set lTarget = Target
End If
End Sub

All tables begin in diferent rows. This example start in 16 row but i put the code in all the pages and adapt to the needs of the specific row number. 
I've already tried to change the code from EntireRow to Range ("I16:J43") but the cells were in the range became all painted with the code color.
Already try a diferent way through the "conditional formatting" with the formula =E($I16<>"";LIN()=CÉL("lin")) in the range $I16:$J43, and in the developer "worksheet", with "Application.Calculate" and it works. I change in the 37 worksheets but i was copying and data from the previous file to this new one and I noticed that the options to paste "values", etc, disappear from my dashboard. The code must be executing something that, like clicking on the cell, no longer lets it paste. A single option was to paste with CTRL+V.
If someone can help me with the code, i'll delete the VBA "Application.Calculate" to to get back to the available collage options.
Thak you for your help.

Luís Lopes
This comment was minimized by the moderator on the site
Hello, the code used to work for a while, but now it doesn't anymore. What can there be wrong?
This comment was minimized by the moderator on the site
Hi Rens Borburgh,There are two codes provided in the post, which one did you use? Did you get any error prompt?
This comment was minimized by the moderator on the site
I have tried them both at the same time. After copying it to a usb stick it didn't work anymore.
This comment was minimized by the moderator on the site
Hi Rens Borburgh,I don't quite understand what you mean. The codes should be used in the sheet code window and not in the Module window. Or can you provide a screenshot of your code window?
This comment was minimized by the moderator on the site
Hi, I am trying to use the double click option to change a cell to green but i also want that cell to go back to no fill or white if i double click it whilst it is green. Is this possible? 
This comment was minimized by the moderator on the site
alguien que me ayude solo quiero que al hacerle click a una celda se ponga de un color y que se mantenga ese color y si le vuelvo hacer click regrese el color original que tenia
This comment was minimized by the moderator on the site
How to highlight the cell(with data) to automatically highlight the other cells (data which is related another data in a previous cell) with click of the cell.Can i do it. Is there a way to do it.
This comment was minimized by the moderator on the site
The code works as long as I do not protect the worksheet. Once I protect the worksheet, because I have conditional formatting on locked cells, the code will not work. How can I change this so that it works on locked worksheet where the user can select unlocked cells?
This comment was minimized by the moderator on the site
Hi,
is it possible to have a code for "change cell color when clicking on it" in the way that it will not change already formated cells with another color, please?
After applying your code all my formating (colours) is away. Thank you. Veronika
This comment was minimized by the moderator on the site
Thank you. Great Job
This comment was minimized by the moderator on the site
hi
the is working grate but i want that the color should only be when the cell is selected and when i select something else, the first cell i selcted should not be colored
can you help me pls with this thanks
This comment was minimized by the moderator on the site
I had that exact same question! I hope someone will answer you! The reason I am looking for this is I have a spreadsheet I use daily and put in lots of information into single cells. It gets hard to see the values (visually, it runs into info in other cells), and would be a great feature if I could change the color of the cell being edited - only while it is being edited. The simplest solution I can think of is that the cell value would be set back to what it was prior to being clicked on - but I don't know how to do that.
This comment was minimized by the moderator on the site
Hi, I am trying to figure out how to change the color of a cell, based on a selection from a dropdown list. For example, HIGH=red, MEDIUM=yellow, LOW=green.

Any tips you can provide are greatly appreciated. Thank You
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