将一系列单元格加载到单个表单文本框中

时间:2017-04-06 19:33:36

标签: excel vba excel-vba

我正在使用MSO Excel 2013,我正在尝试将一系列单元格加载到表单中的单个文本框中。这是我正在撰写的帮助文件。只要我加载1个单元格,它就可以正常工作。当我尝试加载一系列单元格时,出现错误。有没有办法让这项工作?我的代码如下:

Private Sub cmbTopic_Change()
Me.lblTopic.Caption = Me.cmbTopic.Value

Select Case Me.lblTopic.Caption
    Case Is = "Understanding The Software"
        Me.txtHelp.Text = Worksheets("HelpFile").Range("A2").Text
    Case Is = "First Time Use"
        Me.txtHelp.Text = Worksheets("HelpFile").Range("B2").Text
    Case Is = "General Instructions"
        'this is where I'm getting an error
        Me.txtHelp.Text = Worksheets("HelpFile").Range("C2:C4").Text

End Select
End Sub

1 个答案:

答案 0 :(得分:0)

您需要构造一个单元格值字符串,然后将其写入文本框。

您可以尝试这样的事情......

Dim Cell As Range
For Each Cell In Sheet2.Range("C2:C4")
    If Str = "" Then
        Str = Cell.Value
    Else
        Str = Str & vbCrLf & Cell.Value
    End If
Next Cell
Me.txtHelp.MultiLine = True
Me.txtHelp.Value = Str