【发布时间】:2016-07-21 06:25:18
【问题描述】:
我在用户表单中有 27 个标签(例如标签 500 到 526),每个标签都必须从一个范围(sheet1-范围 b4 到 b30)中选择名称。如果标签名称为空,则应隐藏相应的文本框(文本框 500 到 526)。在循环此代码时需要帮助。
proviate sub teamlistchange()
Label500.Caption = Worksheets("SME - Data classification").Range("b4").Value
Label501.Caption = Worksheets("SME - Data classification").Range("b5").Value
Label502.Caption = Worksheets("SME - Data classification").Range("b6").Value
Label503.Caption = Worksheets("SME - Data classification").Range("b7").Value
Label504.Caption = Worksheets("SME - Data classification").Range("b8").Value
Label505.Caption = Worksheets("SME - Data classification").Range("b9").Value
Label506.Caption = Worksheets("SME - Data classification").Range("b10").Value
Label507.Caption = Worksheets("SME - Data classification").Range("b11").Value
Label508.Caption = Worksheets("SME - Data classification").Range("b12").Value
Label509.Caption = Worksheets("SME - Data classification").Range("b13").Value
Label510.Caption = Worksheets("SME - Data classification").Range("b14").Value
Label511.Caption = Worksheets("SME - Data classification").Range("b15").Value
Label512.Caption = Worksheets("SME - Data classification").Range("b16").Value
Label513.Caption = Worksheets("SME - Data classification").Range("b17").Value
Label514.Caption = Worksheets("SME - Data classification").Range("b18").Value
Label515.Caption = Worksheets("SME - Data classification").Range("b19").Value
Label516.Caption = Worksheets("SME - Data classification").Range("b20").Value
Label517.Caption = Worksheets("SME - Data classification").Range("b21").Value
Label518.Caption = Worksheets("SME - Data classification").Range("b22").Value
Label519.Caption = Worksheets("SME - Data classification").Range("b23").Value
Label520.Caption = Worksheets("SME - Data classification").Range("b24").Value
Label521.Caption = Worksheets("SME - Data classification").Range("b25").Value
Label522.Caption = Worksheets("SME - Data classification").Range("b26").Value
Label523.Caption = Worksheets("SME - Data classification").Range("b27").Value
Label524.Caption = Worksheets("SME - Data classification").Range("b28").Value
Label525.Caption = Worksheets("SME - Data classification").Range("b29").Value
Label526.Caption = Worksheets("SME - Data classification").Range("b30").Value
'SDM activities hide empty cells
If Label500.Caption = "" Then TextBox500.Visible = False
If Label501.Caption = "" Then TextBox501.Visible = False
If Label502.Caption = "" Then TextBox502.Visible = False
If Label503.Caption = "" Then TextBox503.Visible = False
If Label504.Caption = "" Then TextBox504.Visible = False
If Label505.Caption = "" Then TextBox505.Visible = False
If Label506.Caption = "" Then TextBox506.Visible = False
If Label507.Caption = "" Then TextBox507.Visible = False
If Label508.Caption = "" Then TextBox508.Visible = False
If Label509.Caption = "" Then TextBox509.Visible = False
If Label510.Caption = "" Then TextBox510.Visible = False
If Label511.Caption = "" Then TextBox511.Visible = False
If Label512.Caption = "" Then TextBox512.Visible = False
If Label513.Caption = "" Then TextBox513.Visible = False
If Label514.Caption = "" Then TextBox514.Visible = False
If Label515.Caption = "" Then TextBox515.Visible = False
If Label516.Caption = "" Then TextBox516.Visible = False
If Label517.Caption = "" Then TextBox517.Visible = False
If Label518.Caption = "" Then TextBox518.Visible = False
If Label519.Caption = "" Then TextBox519.Visible = False
If Label520.Caption = "" Then TextBox520.Visible = False
If Label521.Caption = "" Then TextBox521.Visible = False
If Label522.Caption = "" Then TextBox522.Visible = False
If Label523.Caption = "" Then TextBox523.Visible = False
If Label524.Caption = "" Then TextBox524.Visible = False
If Label525.Caption = "" Then TextBox525.Visible = False
If Label526.Caption = "" Then TextBox526.Visible = False
end sub
【问题讨论】:
标签: vba for-loop label userform caption