Skip i'r prif gynnwys

Sut i gadw fformatio celloedd wrth gyfeirio at gelloedd dalen eraill?

Yn gyffredinol, dim ond wrth gyfeirio at gell arall y mae'r gell yn cadw gwerth y gell, ond yn yr erthygl hon, rwy'n cyflwyno cod VBA i gadw gwerthoedd a fformat y gell wrth gyfeirio at gell arall, ac mae gwerthoedd a fformat y gell yn newid wrth i'r gell gyfeirio newid fel isod screenshot wedi'i ddangos.
doc cadw fformatio wrth gyfeirio 1

Cadwch fformatio celloedd wrth gyfeirio at gell arall gyda VBA


Cadwch fformatio celloedd wrth gyfeirio at gell arall gyda VBA

I drin y swydd hon, does ond angen i chi redeg o dan y cod.

1. Galluogi'r llyfr gwaith rydych chi'n ei ddefnyddio, pwyswch Alt + F11 allwedd i'w galluogi Microsoft Visual Basic ar gyfer Cymhwyso ffenestr, a chliciwch ddwywaith ar enw'r ddalen y byddwch chi'n gosod y gell gyfeirio ynddi Prosiect-VBAProject cwarel i ddangos sgript wag. Yn yr achos hwn, rwyf am gyfeirio at gell A1 yn y Sheet1. Gweler y screenshot:
doc cadw fformatio wrth gyfeirio 2

2. Gludwch y cod isod i'r sgript, ac yn y cod VBA, nodwch y cyfeiriadau celloedd yn ôl yr angen.

VBA: Cadwch fformatio a gwerthoedd wrth gyfeirio at gell arall

Private Sub Worksheet_Activate()
'UpdatebyExtendoffice20101024
    Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Or Target.Value = "" Then Exit Sub
    Application.EnableEvents = False
    If Not Intersect(Target, Range("A1")) Is Nothing Then              'Range("A1") the reference cell
        Target.Copy
        ActiveWorkbook.Sheets("Sheet2").Range("B1").PasteSpecial xlPasteAllUsingSourceTheme
                    'Range("B1")the cell linked to reference cell,ActiveWorkbook.Sheets("Sheet2")the sheet which contains linked cell
        Application.CutCopyMode = False
        Target.Select
    End If
    Application.EnableEvents = True
End Sub

Nodyn: A1 yw'r gell gyfeirio, B1 in Taflen 2 yw'r gell rydych chi am ei chysylltu â'r gell gyfeirio a chadw gwerthoedd a fformatio gydag A1 yn Shee1.

Yna pan fyddwch chi'n newid y gwerthoedd neu'r fformatio yng nghell A1 yn Nhaflen 1, bydd y gell B1 yn Sheet2 yn cael ei newid wrth glicio yn y gell gyfeirio ddwywaith.


Cyfrif yn ôl Lliw

Mewn rhai achosion, efallai bod gennych chi ystod o galwadau gyda lliwiau lluosog, a'r hyn rydych chi ei eisiau yw cyfrif / symio gwerthoedd yn seiliedig ar yr un lliw, sut allwch chi gyfrifo'n gyflym?
Gyda Kutools ar gyfer Excel's Cyfrif yn ôl Lliw, gallwch chi wneud llawer o gyfrifiadau yn gyflym yn ôl lliw, a hefyd gallwch gynhyrchu adroddiad o'r canlyniad a gyfrifwyd.
cyfrif doc yn ôl lliw

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, I would like to keep the format of my reference cell. However, even with your VBA it doesn't work. Can you help me please?
I would like my B2 cell of my sheet 1 to be my reference cell for my C2 cells of sheets 2,3,4,5,6,7.
My document is a list of people, therefore I will have several cells of references not the continuation.
Thanks in advance
This comment was minimized by the moderator on the site
No tienes uno que sea dentro del mismo archivo
This comment was minimized by the moderator on the site
Thanks for sharing this. I have a range of cells in WorksheetA, Sheet1, Range G3:G3000 that I want to reference in WorksheetB, Sheet1, Range G3:G3000. I need WorksheetB, Sheet1, Range G3:G3000 to display both the value and the format of the referenced cells in WorksheetA, Sheet1, G3:G3000. Is there a VBA script that will allow for this?
This comment was minimized by the moderator on the site
Thanks for sharing this. Is there a VBA script that allows for referencing a range of cells in one workbook and then displaying the value and format of the referenced cells in a different workbook?
This comment was minimized by the moderator on the site
Thank you so much for the script. Can you tell me if there is a way for the linked cell to update without having to double click on the reference cell? Thank you!
This comment was minimized by the moderator on the site
hello, I believe this may be just what I am looking for. I need the referenced text to have the same colors and features from the referenced page. The only thing different about mine is that I am pulling from a larger range. I have never used VBA before so I wanted to confirm before I did changes. I am pulling from a document (sheet 2) onto (sheet 1) document. I have used IF formulas to do this, so it returns a value from 3 different columns and they are not in a row. The columns are F,H,J. Could you please help me figure out how I can make this work?
This comment was minimized by the moderator on the site
I am dealing with similar issue. I have a formula in column C, which takes value from the same row, column A. (But only IF B3 is not x AND A3 is not empty):

=IF(B3="x";"y";IF(A3="";"z";A3))

Cells of column A look like this: OK 2019_12_03
But "OK" is in bold format. I would like to keep this format.
I want this for hundreds of cells, so clicking or writing a script for each one of them is undesirable. Any ideas if such feature exists? I'd appreciate some kind of "WITHFORMAT()" function that I could put in the formula, so the following formula would keep the original format:

=IF(B3="x";"y";IF(A3="";"z";WITHFORMAT(A3)))
This comment was minimized by the moderator on the site
Sorry, your problem is a bit complex, I do not understand clearly.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations