gpt4 book ai didi

范围格式中每个单元格的 VBA 百分比

转载 作者:行者123 更新时间:2023-12-04 16:58:20 31 4
gpt4 key购买 nike

我四处寻找这个,它看起来很简单,但我无法让它工作。

我有一张表格,其中一列需要格式化为百分比。下面是我的代码,但它没有格式化单元格,它只是将它们保留为小数。

我想这是因为 cell ,即使声明为范围,实际上是单元格的值,所以我不知道如何引用该范围。

我的 returnRebate变量被声明为一个范围,并且循环在正确的范围内循环。

代码:

Dim cell As Range, p As Double
For Each cell In returnRebate
p = cell.Value

If p <> 0 And p > 1 Then
p = p * 0.01
cell.Value = p
cell.NumberFormat = "Percent" 'Not formatting here
ElseIf p < 1 And p > 0 Then
'do nothing to it
Else
cell.Value = vbNullString
End If
Next

最佳答案

尝试替换 .NumberFormat='Percent'.NumberFormat="0.00%"

关于范围格式中每个单元格的 VBA 百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42844778/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com