我正在编写一个宏,用于格式化每日报告;其中一部分比较了每周的百分比变化。我更喜欢使用“ +0%;-0%”格式,而不是标准的“ 0%;-0%”格式,但是当我应用过滤器时,我丢失了数字上下文以及相关的数字过滤器选项(例如“高于平均水平”)。
有什么想法吗?
我尝试将值复制/粘贴为值,而不是离开公式,尽管它似乎固定了第一个Col百分比范围,但并没有固定其他值(尽管它们已正确粘贴为值)
''''''''
''Call my FindAll function to find each column with the header "% chg"
''''''''
Dim matches As Collection, m
Dim mycell As Range, c As Range
Dim strFindMe As String
Dim myCell As Range
strFindMe = "% Chg"
Set matches = FindAll(rgHeader, strFindMe)
For Each m In matches
Dim ColPct As Range
Set c = m.Offset(1, 0)
Set ColPct = Range(c.Address, Cells(RgSummary.Row, _
Range(c.Address).Column))
''''''''
''Calculate the wk-wk % chg for each column with header "% Chg"
''''''''
For Each myCell In ColPct
''calculate Prct Chg
myCell.FormulaR1C1 = "=iferror(IF(AND(rc[-6]<>"""",rc[-3]<>""""),(rc[-3]/rc[-6]-1),""""),""N/A"")"
' myCell.NumberFormat = "+0%;-0%"
Next
With ColPct
.Copy
.PasteSpecial xlValues
.NumberFormat = "+0%;-0%"
End With
next m
目标:百分比变化格式为“ +0%;-0%”,并由excel过滤器读取为数字,而不是字符串
答案 0 :(得分:0)
原来不是数字格式,它是公式的一部分,如果“然后”在我的列中留下了不可见的文本字符串
使用我在此处ElderDelp处找到的这段代码修复了此问题,谢谢,伙计!
Return empty cell from formula in Excel
For Each myCell In ColPct
''calculate Prct Chg
myCell.FormulaR1C1 = "=iferror(IF(OR(rc[-6]<>"""",rc[-3]<>""""),(rc[-3]/rc[-6]-1),""""),""N/A"")"
myCell.NumberFormat = "+0%;-0%"
If Len(myCell.Text) = 0 Then
myCell.ClearContents
End If
Next