excel - 这个公式的大部分中的子定义错误?
问题描述
我记录了一个条件格式公式,但我想让它动态化。我知道我需要添加LastRow
类似的东西,但我一直把报价搞砸了。
这是它记录的:
Formula1:"=CA$50452>=LARGE($CA$50452:$DO$50452,10)"
但我想让它像这样:
Formula1:"=CA2:CA" & LastRow >= "Large(CA2:CA" & LastRow & ")", 10)
但我不断收到公式部分的Sub-defined
错误。LARGE
有什么想法吗?
脚本的其余部分:
Sub Top10()
Dim ws As Worksheet
Set ws = Worksheets("Sheet111")
Dim LastRow As Long
LastRow = Range("CA" & Rows.Count).End(xlUp).Row
Dim LastCol As Long
LastCol = ws.Cells(LastRow, ws.Columns.Count).End(xlToLeft).Column
ws.Range(ws.Cells(LastRow + 1, "CA"), ws.Cells(LastRow + 1, LastCol)).Formula = "=SUM(CA2:CA" & LastRow & ")"
Range("CA2").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=CA2:CA" & LastRow & ">=LARGE(CA2:CA" & LastRow & "), 10)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = -0.249946592608417
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
解决方案
Formula1:"=CA" & LastRow + 1 & " >= Large(" & ws.Range(ws.Cells(LastRow + 1, "CA"), ws.Cells(LastRow + 1, LastCol)).Address(1,1) & ", 10)"
同时删除该行:
Range("CA2").Select
并替换所有Selection
和:
ws.Range(ws.Cells(2, "CA"), ws.Cells(2, LastCol))
推荐阅读
- python - 从将我的系列索引和数据框列映射到关键熊猫 python 的系列或字典中向数据框添加新列
- vue.js - Vue - 如何使用“导出默认值”添加自定义指令和类定义
- javascript - 使用python单击按钮后获取值
- java - 错误:通过 maven 打包时无法找到或加载主类 jar
- typescript - Typescript:如何引用接口属性的名称?
- r - Nested if statement within for loop
- c++ - C ++缓冲区大小是否有限制..?
- typescript - 如何使用reduce替换打字稿中的过滤器和映射
- javascript - 如何为动画结束事件设置事件监听器
- c# - 使用 EF 查询记录返回空 GUID 主键,而它不是