使用字符串激活工作表

时间:2014-01-15 14:15:44

标签: string vba variables

在这里遇到一些问题......我想要我的工作表(“运输中”)或(“收件箱”) 所以工作表(“在变量中”)我使用按钮标题来提供我的输入 这就是我所拥有的

    Dim department1 As String
    department1 = Area.Caption
    Dim department2 As String
    department2 = toarea.Caption
    Dim ws1 As String
    ws1 = Chr(34) & "In " & department1 & Chr(34)
    Dim ws2 As String
    ws2 = Chr(34) & "In " & department2 & Chr(34)

    MsgBox Chr(34) & "In " & department2 & Chr(34)

    Dim slot1 As String
    slot1 = Worksheets(ws1).Range("I1")
    Dim slot2 As String
    slot2 = Worksheets(ws2).Range("I1")

但它在SLOT1上失败而且SLOT2没有看到工作表(ws1)。范围(“I1”)在范围内

1 个答案:

答案 0 :(得分:0)

我认为你要重现的是:

Worksheets("In shipping")使用变量而不是特定字符串。

要实现这一目标,您无需添加任何额外的"

例如,要准确再现,请尝试以下操作:

department1 = "shipping" 'eventually replace with Area.Caption
ws1 = "In " & department1
slot1 = Worksheets(ws1).Range("I1")