Userform - Labelcontrol with value get frame (VBA)

jammerdk

New Member
Joined
Feb 3, 2010
Messages
49
Hi Guys

I'm currently using this piece of VBA code give certain labels in my userform a frame.

Dim oCtrl As Control

For Each oCtrl In Me.Controls
If TypeName(oCtrl) = "lbl" Then
oCtrl.BorderStyle = 1
End If
Next oCtrl

I'd like to include if labels caption contains a value..

Hope you're able to lead me on the way
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Perhaps.
Code:
Dim oCtrl As Control

    For Each oCtrl In Me.Controls
        If TypeName(oCtrl) = "lbl" Then
            If oCtrl.Caption Like "*value*" Then
                oCtrl.BorderStyle = 1
            End If
        End If
    Next oCtrl
 
Last edited:
Upvote 0
Hi Guys

I'm currently using this piece of VBA code give certain labels in my userform a frame.

Dim oCtrl As Control

For Each oCtrl In Me.Controls
If TypeName(oCtrl) = "lbl" Then
If oCtrl.Caption <> "" Then oCtrl.BorderStyle = 1
End If
Next oCtrl

I'd like to include if labels caption contains a value..

Hope you're able to lead me on the way
What you are asking is not clear. Perhaps what I show in red above is what you are after.
 
Upvote 0
In general this is what I'm trying to achieve.

If Me.lblMax1.Caption = "" Then Me.lblMax1.BorderStyle = fmBorderStyleNone
If Me.lblMax2.Caption = "" Then Me.lblMax2.BorderStyle = fmBorderStyleNone
.
.
.
.
If Me.lblMin1.Caption = "" Then Me.lblMin1.BorderStyle = fmBorderStyleNone
If Me.lblMin2.Caption = "" Then Me.lblMin2.BorderStyle = fmBorderStyleNone
.
.
.
I just want to cycle through all label controls instead of have to do it 1 by 1 :eeek: as there quite a few label controls located in my userform.
 
Upvote 0
Try this:
Code:
Private Sub CommandButton2_Click()
Dim ctrl As MSForms.Control
 
    For Each ctrl In Me.Controls
    
        If TypeOf ctrl Is MSForms.Label Then
            If ctrl.Caption = "" Then ctrl.BorderStyle = fmBorderStyleNone
        End If
    Next ctrl
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top