文本框值不会根据VBA中的选项按钮值进行更改

  • 本文关键字:按钮 选项 VBA 文本 excel vba
  • 更新时间 :
  • 英文 :


我正在使用excel VBA创建一个价格计算器。根据单位选择为公制或英制,我希望在文本框中除了值之外还显示适当的单位。

这是我尝试过的代码,但它不起作用。

If cmButton.Value = True Then
Cells(emptyRow, 5) = "Metric"
TextBox1.Value = "cm"
TextBox2.Value = "cm"
TextBox3.Value = "cm"
TextBox4.Value = "g"
End If

If inchButton.Value = True Then
Cells(emptyRow, 5) = "Imperial"
TextBox1.Value = "inch"
TextBox2.Value = "inch"
TextBox3.Value = "inch"
TextBox4.Value = "oz"

End If

我希望代码看起来更像这样:-

Private Sub cmButton_Click()
Cells(emptyRow, 5) = "Metric"
TextBox1.Value = "cm"
TextBox2.Value = "cm"
TextBox3.Value = "cm"
TextBox4.Value = "g"
End Sub
Private Sub inchButton_Click()
Cells(emptyRow, 5) = "Imperial"
TextBox1.Value = "inch"
TextBox2.Value = "inch"
TextBox3.Value = "inch"
TextBox4.Value = "oz"
End Sub

最新更新