首页 > 解决方案 > 使用不同的多个复选框写入同一个单元格

问题描述

我试图让不同的多个复选框写入同一个单元格而不覆盖以前的信息。

If CheckBox13.Value = True _
    Then
    Range("A1").Value = "True 1"
End If

If CheckBox14.Value = True _
    Then
    Range("A1").Value = Range ("A1").Value + "True 2"
End If

这看起来准确吗?

标签: excelvbacheckboxuserform

解决方案


利用控件的默认属性,您可以使用如下内容:

Range("A1") = ""

If CheckBox1 Then Range("A1") = "True 1"
If CheckBox2 Then Range("A1") = Range("A1") + ", True 2"
If CheckBox3 Then Range("A1") = Range("A1") + ", True 3"
If CheckBox4 Then Range("A1") = Range("A1") + ", True 4"

If (Range("A1") <> "") And (Left(Range("A1"), 1) = ",") Then
  Range("A1") = Mid(Range("A1"), 3)
End If

推荐阅读