Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to keep cell formatting while referencing other sheet cells?

Generally, the cell only keeps the cell value while referencing other cell, but in this article, I introduce a VBA code to keep the cell values and formatting while referencing another cell, and the cell values and formatting changes as the reference cell changes as below screenshot shown.
doc keep formatting while referencing 1

Keep cell formatting while referencing another cell with VBA


Keep cell formatting while referencing another cell with VBA


To handle this job, you just need to run below code.

1. Enable the workbook you use, press Alt + F11 key to enable Microsoft Visual Basic for Application window, and double click on the sheet name which you will place the reference cell in Project-VBAProject pane to show a blank script. In this case, I want to refer to cell A1 in the Sheet1. See screenshot:
doc keep formatting while referencing 2

2. Paste below code to the script, and in the VBA code, specify the cell references as you need.

VBA: Keep formatting and values while referencing another cell

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

Note: A1 is the reference cell, B1 in Sheet 2 is the cell you want to link to the reference cell and keep values and formatting with A1 in Shee1.

Then when you change the values or formatting in cell A1 in Sheet1, the cell B1 in Sheet2 will be changed while clicking at the reference cell twice.


Count by Color

In some cases, you may have a range of calues with multiple colors, and what you want is to count/sum values based on same color, how can you quickly calculate?
With Kutools for Excel's Count by Color, you can quickly do many calculations by color, and also can generate a report of the calculated result.
doc count by color


Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
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.
    Mato · 27 days ago
    No tienes uno que sea dentro del mismo archivo
  • To post as a guest, your comment is unpublished.
    Dustin · 5 months ago
    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?
  • To post as a guest, your comment is unpublished.
    Dustin · 5 months ago
    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?
  • To post as a guest, your comment is unpublished.
    Justin · 6 months ago
    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!
  • To post as a guest, your comment is unpublished.
    Amy Napier · 8 months ago
    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?
    • To post as a guest, your comment is unpublished.
      Sunny · 8 months ago
      Sorry, your problem is a bit complex, I do not understand clearly.