Propagate labels from Worksheet

G

Guest

I was able to VB a label to show on a user form from a worksheet.

Private Sub UserForm_Click()

With Label1
.Caption = Worksheets("Sheet1").Range("B4") '
.AutoSize = True
.WordWrap = False
.Font.Name = "Times New Roman"
.Font.Size = 14
.Font.Bold = True
End With

End Sub

How do I propagate the labels with the Range title from the worksheet (Range
B4:B7) stopping at the first encountered empty cell? Also I have to click on
the form to show the actual label before the label caption shows-up. Could I
do it instantaneously?

Thanks a lot.

Ligaya
 
D

Dave Peterson

You have 4 labels (label1, label2, ..., label4)?

If yes:

Option Explicit
Private Sub UserForm_Initialize()

Dim iCtr As Long
Dim myRng As Range

Set myRng = Worksheets("sheet1").Range("b4:b7")

For iCtr = 1 To 4
With Me.Controls("label" & iCtr)
If myRng(iCtr).Value = "" Then
Exit For
'or
'.Caption = ""
Else
.Caption = myRng(iCtr).Text
.AutoSize = True
.WordWrap = False
.Font.Name = "Times New Roman"
.Font.Size = 14
.Font.Bold = True
End If
End With
Next iCtr

End Sub
 
G

Guest

Dave Peterson said:
You have 4 labels (label1, label2, ..., label4)?

If yes:

Option Explicit
Private Sub UserForm_Initialize()

Dim iCtr As Long
Dim myRng As Range

Set myRng = Worksheets("sheet1").Range("b4:b7")

For iCtr = 1 To 4
With Me.Controls("label" & iCtr)
If myRng(iCtr).Value = "" Then
Exit For
'or
'.Caption = ""
Else
.Caption = myRng(iCtr).Text
.AutoSize = True
.WordWrap = False
.Font.Name = "Times New Roman"
.Font.Size = 14
.Font.Bold = True
End If
End With
Next iCtr

End Sub

Dave,

Thanks. I'll try that approach .


Regards.

Ligaya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top