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.
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:
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.
|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.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
- To post as a guest, your comment is unpublished.· 1 years agoNo tienes uno que sea dentro del mismo archivo
- To post as a guest, your comment is unpublished.· 1 years agoThanks 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.· 1 years agoThanks 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.· 1 years agoThank 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.· 2 years agohello, 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.· 1 years agoI 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):
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:
- To post as a guest, your comment is unpublished.· 2 years agoSorry, your problem is a bit complex, I do not understand clearly.