Search code examples
excelvbauserform

Changing label caption on UserForm


I am trying to use a "x + 1" function to change a label in a UserForm. The label caption is not changing.

My label (SalesForm.BHSDROWLABELLF) caption being 1, I want to click a button and turn the caption from 1 to 2.

Private Sub BHSDNEXTTAPBUTTONLF_Click()

X = SalesForm.BHSDROWLABELLF.Caption

X = X + 1

SalesForm.BHSDADDRESSLF.Value = Worksheets("GG").Cells(X, 23)
End Sub

Solution

  • Your code can be drastically reduced to

    Private Sub BHSDNEXTTAPBUTTONLF_Click()
        With BHSDROWLABELLF
            .Caption = Val(.Caption) + 1
    
            BHSDADDRESSLF.Value = Worksheets("GG").Cells(.Caption, 23)
        End With
    End Sub
    

    I am assuming that the name of the form is SalesForm