我想根据单元格组合更改标签。例如,我有 5 列可以在标签中显示。但我只显示非空白的列。Label.Caption = Column A、Column C 和 Column D 我如何在 VBA 中的 Label.Caption 中表达这一点?谢谢
答案1
像这样
Sub Henrique()
Dim labelRow As Long
Dim labelText As String
Dim i As Long
labelRow = 1
For i = 1 To 5
If Not IsEmpty(Sheet1.Cells(labelRow, i)) Then
labelText = labelText & Sheet1.Cells(labelRow, i) & " "
End If
Next
labelText = Trim$(labelText)
With UserForm1.Label1
.Caption = labelText
End With
End Sub