發表文章

目前顯示的是有「Excel」標籤的文章

【Excel VBA應用】計算骰子的平均點數及全距

上一篇介紹了如何丟出五顆骰子,這次延續主題,教大家如何計算五顆骰子的平均值及全距,並寫入預定的儲存格內。 Excel VBA語法如下: '設定迴圈次數,可以隨喜好設定上限值 For i = 1 To TextBox8.Value                  '隨機骰出五顆骰子的點數         TextBox1.Value = Int((ComboBox1.Value - ComboBox6.Value + 1) * Rnd + ComboBox6.Value)         TextBox2.Value = Int((ComboBox2.Value - ComboBox7.Value + 1) * Rnd + ComboBox7.Value)         TextBox3.Value = Int((ComboBox3.Value - ComboBox8.Value + 1) * Rnd + ComboBox8.Value)         TextBox4.Value = Int((ComboBox4.Value - ComboBox9.Value + 1) * Rnd + ComboBox9.Value)         TextBox5.Value = Int((ComboBox5.Value - ComboBox10.Value + 1) * Rnd + ComboBox10.Value)                  '計算五顆骰子的平均點數         TextBox6.Value = WorksheetFunction.Average(TextBox1.Value, TextBox2.Value, TextBox3.Value, TextBox4.Value, TextBox5.Value)    ...

【Excel VBA應用】 如何製作一顆可以調整點數上下限的骰子

VBA程式語法: Int((ComboBox1.Value - ComboBox2.Value + 1) * Rnd + ComboBox2.Value) 其中 ComboBox1.Value為骰子上限的下拉式選單,預設為一到六 ComboBox2.Value為骰子下限的下拉式選單,預設為一到六 此語法可以 產生範圍由一到六的隨機亂數 ,相當於骰出一顆骰子,這對我們建構骰子SPC是重要的第一步。