2016-04-01 16 views
0

Kullanıcı formunda 27 etiketim var (500 - 526 arası etiketler var) ve her etiketin bir aralıktan ad seçmesi gerekiyor (sayfa1-4 arası b4 - b30). Etiket adı boşsa, ilgili metin kutusu (metin kutusu 500 ila 526) gizlenmelidir. Bu kodu döngülemek için yardıma ihtiyacınız var. BöyleDöngü Kullanıcı adlarını kullanıcı formunda toplama metnindeki metinler

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 

cevap

0

deneyin şey: Bu yardımcı olur

proviate Sub teamlistchange() 

Dim i As Integer 

For i = 500 To 526 

Controls("Label" & i).Caption = Worksheets("SME - Data classification").Range(Cells(i,2)).Value 
If Controls("Label" & i).Caption = "" Then Controls("TextBox" & i).Visible = False 

Next i 

Umut!

+0

Teşekkür End Sub. ("KOBİ - Veri sınıflandırma") Aralığı (Hücreler (i, 2)) Değer " –

+0

" Çalışma Sayfaları ("KOBİ - Veri sınıflandırması") Aralık (Hücreler (i, 2)) Değeri "Burada aralık b4 ila b30. –

+0

Bunun için bir çözüm bulmada herhangi bir şans? –

0

Çözümlendi!

Private Sub TeamListChange() 

Const iCONTROL_NO_FIRST As Integer = 500 
Const iCONTROL_NO_LAST As Integer = 526 
Const sPREFIX_TEXTBOX As String = "TextBox" 
Const sPREFIX_LABEL  As String = "Label" 
Const sLABEL_COLUMN  As String = "B" 
Const sSHEET_NAME  As String = "SME - Data classification" 
Const iOFFSET   As Integer = 496 

Dim iLabelRowNo   As Integer 
Dim sLabelText   As String 
Dim rLabelCell   As Range 
Dim iControlNo   As Integer 
Dim wks     As Worksheet 

Set wks = ThisWorkbook.Worksheets(sSHEET_NAME) 

With Me 

    For iControlNo = iCONTROL_NO_FIRST To iCONTROL_NO_LAST 

     iLabelRowNo = iControlNo - iOFFSET 

     Set rLabelCell = wks.Range(sLABEL_COLUMN & CStr(iLabelRowNo)) 

     sLabelText = rLabelCell.Value 

     .Controls(sPREFIX_LABEL & CStr(iControlNo)).Caption = sLabelText 

     If sLabelText = vbNullString Then 
      .Controls(sPREFIX_TEXTBOX & CStr(iControlNo)).Visible = False 
     End If 

    Next iControlNo 

End With 

hızlı tepki, ancak ben "Controls için bir hata mesajı alıyorum (" Etiket" & i) .Caption = Çalışma sayfaları için

İlgili konular