Fer*_*roc 3 format microsoft-excel-2010
我想在 Excel 的单元格中使用以下格式:
123g 99s 99c
Run Code Online (Sandbox Code Playgroud)
100 铜 (c) = 1 银 (s)
100 银 = 1 金 (g)
所以,如果我输入12394它会显示为“1g 23s 94c”。
这有可能吗?
试试这个自定义格式:
#0"g" #0"s" 00"c"
Run Code Online (Sandbox Code Playgroud)
请注意,无论实际数量如何,这都会显示所有三个“单位”,因此12将显示为“0g 0s 12c”。如果您只想显示非零数量的最大“单位”(例如12“12c”,598“5s 98c”等),您可以按如下方式调整它,以实际应用不同的格式价值:
[>=10000]#0"g" #0"s" 00"c";[>=100]#0"s" 00"c";#0"c"
Run Code Online (Sandbox Code Playgroud)
它并不完美,例如10245将显示为“1g 02s 45c”,而不是“1g 2s 45c”,因为它只是拆分单元格值而不是将其除以 100 以获得单个金额,但除此之外它应该做你想做的。
要处理负值,您将不得不将上述格式与条件格式结合起来,因为 Excel 在单一数字格式中最多只能有 3 个条件。尝试以下操作(我假设 Excel 2010,也应该在 2007 年工作,不确定早期版本):
=A1>=0,然后单击“格式...”[>=10000]#0"g" #0"s" 00"c";[>=100]#0"s" 00"c";#0"c"=A1<0,然后单击“格式...”[<=-10000]-#0"g" #0"s" 00"c";[<=-100]-#0"s" 00"c";#0"c"如果您需要修改或删除格式规则,或将其扩展以应用于更多单元格,只需转到“条件格式”→“管理规则”。
另一种选择是使用 VBA 函数来格式化值。按Alt+F11打开 VBA 编辑器,在 Project 窗口中右键单击并选择 Insert → Module,然后粘贴以下代码(当然,这只是编写此类函数的众多方法之一):
Function MyFormat(intValue)
Dim strReturn As String
If intValue < 0 Then strReturn = "-"
intValue = Abs(intValue)
If intValue > 10000 Then
strReturn = strReturn & Fix(intValue / 10000) & "g"
intValue = intValue - (Fix(intValue / 10000)) * 10000
End If
If intValue > 100 Then
If Len(strReturn) > 0 Then strReturn = strReturn & " "
strReturn = strReturn & Fix(intValue / 100) & "s"
intValue = intValue - (Fix(intValue / 100)) * 100
End If
If Len(strReturn) > 0 Then strReturn = strReturn & " "
strReturn = strReturn & intValue & "c"
MyFormat = strReturn
End Function
Run Code Online (Sandbox Code Playgroud)
与使用自定义数字格式相比,这种方法为您提供了更大的灵活性,并且比管理条件格式规则更易于使用 - 只需键入=MyFormat(12345)而不是12345. 但是,缺点是您无法对数据执行数学运算,因为 Excel 现在将值视为文本,而不是数字。
| 归档时间: |
|
| 查看次数: |
5758 次 |
| 最近记录: |