Namig: drugi jeziki so prevedeni v Google. Lahko obiščete English različico te povezave.
Vpiši se
x
or
x
x
Registracija
x

or

Kako nastaviti celično barvo, ki je enaka drugi barvi celice v Excelu?

Če želite barvo celice ujemati z drugo, vam lahko ta metoda pomaga.

Nastavi barvo celice enako drugi barvi celice s kodo VBA


Nastavi barvo celice enako drugi barvi celice s kodo VBA


Spodnja metoda VBA vam lahko pomaga, da v Excelu nastavite barvo celice, ki je enaka drugi. Prosimo, naredite na naslednji način.

1. Na delovnem listu se morate ujemati z barvo dveh celic, prosim z desno miškino tipko kliknite zavihek stanja in nato kliknite Ogled kode iz menija z desnim klikom. Prikaz slike:

2. V odprtju Microsoft Visual Basic za aplikacije okno, morate kopirati in prilepiti kodo VBA v okno Code.

VBA koda: nastavite barvo celice enako drugi barvi celice

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Me.Range("C1").Interior.Color = Me.Range("A1").Interior.Color
End Sub

Opombe: V kodi je A1 celica, ki vsebuje barvo polnila, ki jo boste ujemali s C1. Prosimo, da jih spremenite glede na vaše potrebe.

Potem je celica C1 napolnjena z isto barvo celice A1 kot pod prikazom slike.

Od zdaj naprej, ko se barva polnila v A1 spremeni, se bo C1 ujemal z isto barvo samodejno.


Sorodni članki:



Priporočena orodja za produktivnost za Excel

Kutools za Excel vam pomaga, da vedno končate delo pred časom in izstopite iz množice

  • Več kot zmogljive napredne funkcije 300, zasnovane za 1500 delovne scenarije, ki povečujejo produktivnost z 70%, vam dajejo več časa za skrb za družino in uživanje v življenju.
  • Ne potrebujete več pomnilniških formul in VBA kod, od zdaj naprej pa dajate svojim možganom počitek.
  • Postanite strokovnjak za Excel v minutah 3, zapletene in ponavljajoče se operacije lahko opravite v nekaj sekundah,
  • Vsak dan zmanjšajte število operacij tipkovnice in miške, zdaj se poslovite od poklicnih bolezni.
  • 110,000 visoko učinkovite ljudi in 300 + svetovno priznanih podjetij izbiro.
  • Brezplačna preizkusna različica 60 dneva. 60-dnevno jamstvo vračila denarja. 2 let brezplačne nadgradnje in podpore.

Prinaša kartično brskanje in urejanje za Microsoft Office, veliko močnejši od zavihkov brskalnika

  • Office Tab je namenjen za Word, Excel, PowerPoint in druge Office aplikacije: Založnik, Dostop, Visio in Projekt.
  • Odprite in ustvarite več dokumentov v novih zavihkih istega okna in ne v novih oknih.
  • Z 50% poveča vašo produktivnost in vsak dan zmanjša na stotine klikov z miško!
Say something here...
symbols left.
You are guest ( Sign Up? )
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.
    Tony · 4 months ago
    As Chris I am interested in copying the background color from another worksheet?
  • To post as a guest, your comment is unpublished.
    Chris · 4 months ago
    I found your code to 'set cell color to equal to another cell color" and it works when I am using it on the same worksheet ( ex from cell A1 to cell A2). I am wondering if there is a way to have this same functionality from another worksheet (ex to copy cell color from sheet1!A1 to sheet2!A1? Any help you could offer would be appreciated!
  • To post as a guest, your comment is unpublished.
    Zack · 7 months ago
    This is a good start to what I am looking to do. But I am looking for something a bit more complicated

    How could I adapt this to apply to multiple rows and a range. For instance I have a header column in Column B, I want cells from G to CS to match the colour of the header row but only is they have something in them ie the letter x. I know I can write an IF and THEN statement but how would I apply it to multiple Rows without writing a code for each row.
  • To post as a guest, your comment is unpublished.
    yesser · 1 years ago
    hi , how to apply the same VBA but on a range of cells for example :

    i want to have the same color of range (C8:X8) to be apply on the range (S16:AL16) one by one in the same order (S16 get the color of C16 , T16 get the color of D8 ....etc)
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      Good day,

      The below VBA code can help you solving the problem. Thanks for your comment.

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim xSRg, xDRg, xISRg, xIDRg As Range
      Dim xFNum As Long
      On Error Resume Next
      Set xSRg = Range("C8:X8")
      Set xDRg = Range("S16:AL16")
      For xFNum = 1 To xSRg.count
      Set xISRg = xSRg.Item(xFNum)
      Set xIDRg = xDRg.Item(xFNum)
      xIDRg.Interior.Color = xISRg.Interior.Color
      Next xFNum
      End Sub
      • To post as a guest, your comment is unpublished.
        Shaun Symmonds · 4 months ago
        Hi

        I am trying to do similar, but I have two spreadsheets (files). Spreadsheet 1 is the Master where the data is manually updated and file (spreadsheet 2) is equalling the data in the same cell as spreadsheet 1. When I open spreadsheet 2, I get a prompt to refresh with spreadsheet 1 no promlems, but if the colour of the cell is changed in spreadsheet 1 it does not update in spreadsheet 2, neither does 'strike-trough' of fonts..help please?
  • To post as a guest, your comment is unpublished.
    JJ · 1 years ago
    Hi, the cell being referenced for colour changes colour based on conditional formatting. The above doesn't seem to work with that and the destination cells are staying blank. How can this be corrected? Thanks
    • To post as a guest, your comment is unpublished.
      LP · 8 months ago
      If you have Excel 2010 or later you can use the DisplayFormat function to return the color of a conditionally formatted cell. See below:

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Me.Range("C1").Interior.Color = Me.Range("A1").DisplayFormat.Interior.Color
      End Sub
    • To post as a guest, your comment is unpublished.
      Marty · 10 months ago
      I have the same problem. Works on cells without conditional formatting but doesn't with those that do