VBA将组合框值设置为多个工作表中的多个单元格

时间:2019-01-15 11:54:09

标签: excel vba

我有3个组合框和一个OK按钮,我需要将多个工作表中的多个单元格的值设置为等于组合框选择的值。

Dim choice As String
Dim x As Variant

x = Array("STD BASE DD", "STD BASE CAB DOOR ONLY", "OPEN BASE CABINET", _
    "1 DRAWER BASE & OPEN", "2 DRAWER BASE", "3 DRAWER BASE", "4 DRAWER BASE", _
    "5 DRAWER BASE")

    choice = matsetup.ComboBox1.Value

   Worksheets(x).Range("H14,H15,H20").Value = choice

这会导致错误“对象不支持属性或方法”

Worksheets(x).Range("H14,H15,H20").Value = choice

有人知道解决方法吗

2 个答案:

答案 0 :(得分:1)

也许您正在寻找类似的东西?

Dim choice As String
Dim x As Variant
Dim v As Variant

x = Array("STD BASE DD", "STD BASE CAB DOOR ONLY", "OPEN BASE CABINET", _
          "1 DRAWER BASE & OPEN", "2 DRAWER BASE", "3 DRAWER BASE", _
          "4 DRAWER BASE", "5 DRAWER BASE")

choice = matsetup.ComboBox1.Text

For Each v In x
    Worksheets(v).Range("H14,H15,H20").Value = choice
Next v

答案 1 :(得分:0)

这行吗?

Worksheets(x).Range("H14").Value = choice
Worksheets(x).Range("H15").Value = choice
Worksheets(x).Range("H20").Value = choice