用户表单中的循环标签名称从工作表范围中挑选文本

时间:2016-04-01 12:32:13

标签: vba for-loop label userform caption

我在userform中有27个标签(例如标签500到526),每个标签必须从一个范围中选择名称(sheet1-范围b4到b30)。如果标签名称为空,则应隐藏相应的文本框(文本框500至526)。在循环此代码时需要帮助。

// Will return a value between 0.0 ... 1.0, based on the decibels
func getIntensityFromPower(decibels: Float) -> Float {
    // The minimum possible decibel returned from an AVAudioPlayer channel
    let minDecibels: Float = -160
    // The maximum possible decibel returned from an AVAudioPlayer channel
    let maxDecibels: Float = 0

    // Clamp the decibels value
    if decibels < minDecibels {
        return 0
    }
    if decibels >= maxDecibels {
        return 1
    }

    // This value can be adjusted to affect the curve of the intensity
    let root: Float = 2

    let minAmp = powf(10, 0.05 * minDecibels)
    let inverseAmpRange: Float = 1.0 / (1.0 - minAmp)
    let amp: Float = powf(10, 0.05 * decibels)
    let adjAmp = (amp - minAmp) * inverseAmpRange

    return powf(adjAmp, 1.0 / root)
}

2 个答案:

答案 0 :(得分:0)

尝试这样的事情:

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

希望这有帮助!

答案 1 :(得分:0)

它解决了!!

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

End Sub