excel - 从其他文件中查找并保持格式
问题描述
我有 33 个不同公司部门的文件,我们在其中保留了员工的工作时间。他们每个人都很少有人在那里工作。
我编写了一个“主”excel,它保存了这 33 个不同文件中的所有数据。我设法编写了几个公式来保持它正确加载数据。但我只有正确的价值观。
我仍然需要加载对我们至关重要的单元格颜色。你有什么想法如何实现吗?我已经看过那个话题,但我不能让它继续工作。也在考虑将文件与 VBA 合并,但没有任何运气 - 我仍然只得到值,而不是单元格的颜色。
解决方案
您可以尝试使用此 UDF 来获取单元格颜色和格式
复制下面的代码Module1,
使用 LookupFormat 作为公式 =LookupFormat(A1,Sheet2!A1:D100,4) 这将获取值以及单元格格式
Public IntClr, IntShade, FntClr, FntShade, CellAdd
Function LookupFormat(ByRef FndValue, ByRef LookupRng As Range, ByRef ColRef As Long)
Set FindCell = LookupRng.Find(What:=FndValue, LookIn:=xlValues)
CellAdd = Application.Caller.Address
With FindCell
FindRow = .Row
FindCol = .Column
With .Offset(0, ColRef - 1)
With .Interior
IntClr = .Color
IntShade = .TintAndShade
End With
With .Font
FntClr = .Color
FntShade = .TintAndShade
End With
LookupFormat = .Value
End With
End With
End Function
将下面的宏复制到工作表模块
Sub Worksheet_Change(ByVal Target As Range)
If CellAdd = "" Then Exit Sub
RefChk = IntClr & IntShade & FntClr & FntShade
If RefChk = "" Then Exit Sub
With Range(CellAdd)
With .Interior
.Color = IntClr
.TintAndShade = IntShade
End With
With .Font
.Color = FntClr
.TintAndShade = FntShade
End With
End With
IntClr = ""
IntShade = ""
FntClr = ""
FntShade = ""
CellAdd = ""
End Sub
参考:https ://quadexcel.com/wp/vlookup-get-cell-color-font-color-along-lookup-value/
编辑:更新了如何使用该 UDF,感谢 Tim
推荐阅读
- javascript - 在没有jQuery的情况下选择具有特定背景颜色的元素
- android - Android 中的 App-Linking、assetlinks.json、IIS,无法正常工作
- python - UnicodeDecodeError:“utf-8”编解码器无法解码位置 108 中的字节 0xd1:无效的继续字节
- python - 来自多个是或否数据框列的汇总矩阵
- sql - 基于两列的任意排序
- c++ - 在 Visual Studio c++ 项目中将 Eigen 外部库放在哪里?
- javascript - How to ensure wasm memory is freed when using it from JavaScript
- python - 遇到此错误“simplejson.errors.JSONDecodeError:预期值:第 1 行第 1 列(字符 0)”
- rest - 如果会话令牌仍在使用中,它们是否应该不会过期?
- postgresql - 如何在 Quarkus 中选择具有反应式数据源的 Postgres 模式