[算表] vba combobox顯示百分比並可做運算
軟體:Excel
版本:2016
因選單需要顯示為百分比
但如果為字串表示則無法做運算
該如何讓Combobox選項數字顯示為百分比"%"
確有辦法讓該值做運算?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.37.216.201
※ 文章網址: https://www.ptt.cc/bbs/Office/M.1505316474.A.9CA.html
→
09/13 23:46, , 1F
09/13 23:46, 1F
→
09/13 23:47, , 2F
09/13 23:47, 2F
→
09/13 23:50, , 3F
09/13 23:50, 3F
→
09/13 23:56, , 4F
09/13 23:56, 4F
→
09/13 23:57, , 5F
09/13 23:57, 5F
感謝S大回覆
經測試結果如下
Private Sub CommandButton5_Click()
Dim s1, s2, s3, s4 As Double
If CheckBox1.Value = True Then
Range("f24").Value = Yes
ElseIf CheckBox2.Value = True Then
Range("f24").Value = No
End If
s1 = Application.WorksheetFunction.Round(-Range("j24").Value *
CDbl(ComboBox7.Value) / 100, 0)
s2 = Application.WorksheetFunction.Round(-Range("j24").Value *
Val(ComboBox7.Value) / 100, 0)
Range("J27").Value = s1
Range("J28").Value = s2
s2 為整數部份 正常可行
s1 帶小數點 ==>執行錯誤13
形態不符合
With ComboBox5
'.List = Array("0.0191")
.List = Array(1.91 & "%")
End With
With ComboBox7
'.List = Array("0.03", "0.1", "0.15", "0.2")
.List = Array(3 & "%", 10 & "%", 15 & "%", 20 & "%")
End With
End Sub
'此行改寫為
s1 = Application.WorksheetFunction.Round(-Range("j24").Value *
Left(ComboBox5.Value,Len(ComboBox5.Value -1), 0))
錯誤訊息為
翻譯錯誤
引數的個數錯誤或指定不了正確的屬性
※ 編輯: JointBank (114.37.216.201), 09/14/2017 00:57:11
※ 編輯: JointBank (114.37.216.201), 09/14/2017 01:02:14
s1 = Application.WorksheetFunction.Round(-Range("j24").Value *
Left(ComboBox5.Value, Len(ComboBox5.Value) - 1) / 100, 0)
執行正常
改怎麼判斷何時該加Application.WorksheetFunction
※ 編輯: JointBank (114.37.216.201), 09/14/2017 01:07:50
→
09/14 07:04, , 6F
09/14 07:04, 6F
→
09/14 07:05, , 7F
09/14 07:05, 7F
→
09/14 07:05, , 8F
09/14 07:05, 8F
→
09/14 07:06, , 9F
09/14 07:06, 9F
→
09/14 09:46, , 10F
09/14 09:46, 10F
→
09/14 09:46, , 11F
09/14 09:46, 11F
→
09/14 10:02, , 12F
09/14 10:02, 12F
→
09/14 10:03, , 13F
09/14 10:03, 13F
→
09/14 10:17, , 14F
09/14 10:17, 14F
→
09/14 10:18, , 15F
09/14 10:18, 15F
→
09/14 10:19, , 16F
09/14 10:19, 16F
→
09/14 10:20, , 17F
09/14 10:20, 17F
→
09/14 10:21, , 18F
09/14 10:21, 18F
→
09/14 10:39, , 19F
09/14 10:39, 19F
→
09/14 10:39, , 20F
09/14 10:39, 20F
Office 近期熱門文章
PTT數位生活區 即時熱門文章