Vba code to loop through a column and return values to label controls

Ben888

New Member
Joined
Sep 2, 2013
Messages
14
I have a column (1,11) to (5,11) where sometimes there is a value of either a number or text (eg. 5, 20, 100, 500, Misc Vol). Sometimes there is only a single value within the column on one of the rows. Often there is multiple (upto 3 values). I'm after vba code that will loop through and ignore the empty cells within the column and once it finds a value, show the value in 'label1' control. Subsequently if it finds an additional value in the column, show that value in 'label2' control. Then repeat if necessary and show that value 'label3' control (if there are three seperate values in the column range). Thankyou for considering the above and any assistance given.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi Ben,

Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim ws As Worksheet
    Dim rngCell As Range
    Dim i As Long
    
    Set ws = ThisWorkbook.Sheets("Sheet1") 'Sheet name containing the values in Col. K to update to UserForm1. Change to suit.
    
    For Each rngCell In ws.Range("K1:K5")
        If Len(rngCell) > 0 And IsNumeric(rngCell) Then
            i = i + 1
            UserForm1.Controls("Label" & i).Caption = rngCell 'Updates the label controls on an userform called 'UserForm1'. Change to suit.
        End If
    Next rngCell
    
    UserForm1.Show

End Sub

Regards,

Robert
 
Upvote 0
Thanks for letting us know and I'm glad we could provide you with a workable solution :cool:
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
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