Populating labels on a userform with values from cells on a worksheet that are NOT hidden...

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I've currently got something that works as far as populating my userform with the names that are located in row 1 within the specified range on the target worksheet... but I am having some trouble with getting the code to work so that it only looks at visible cells and ignores all the other cells that might be hidden.
Here is how it should work:
When the userfom is opened, the "UserForm_Initialize" command takes all the names in row 1 and adds each name to its target label and corresponding text box for that name:
NAMES:
Capture1.JPG

THE SAME NAMES POPULATED ON THE USERFORM AFTER IT IS OPENED:
Capture2.JPG
USERFORM IN VBA BEFORE EXECUTED:
Capture3.JPG

What I need the code to do is to only look at the visible names that are in that row and within the range that it is looking.
For example, when the top row of names is filtered like this:
Capture4.JPG

then the userform would only populate the labels with those names (I understand that this will result with abunch of empty labels present on the useform... but I can live with that) (for now! ;) )

Current code that looks at and captures ALL the names in row 1 and takes each name and places it in each label as it's caption:

VBA Code:
lbl_2.Caption = tm.Range("N1").value
lbl_3.Caption = tm.Range("P1").value
lbl_4.Caption = tm.Range("R1").value
lbl_5.Caption = tm.Range("T1").value
lbl_6.Caption = tm.Range("V1").value
lbl_7.Caption = tm.Range("X1").value
lbl_8.Caption = tm.Range("Z1").value
lbl_9.Caption = tm.Range("AB1").value
lbl_10.Caption = tm.Range("AD1").value
lbl_11.Caption = tm.Range("AF1").value
lbl_12.Caption = tm.Range("AH1").value
lbl_13.Caption = tm.Range("AJ1").value
lbl_14.Caption = tm.Range("AL1").value
lbl_15.Caption = tm.Range("AN1").value
lbl_16.Caption = tm.Range("AP1").value



The code I cant seem to get to work (the code that will only capture those cells that are visible and apply those to each label) looks like this: (only showing 1 line for 1 name, which doesn't work but I've played around with it a number of ways and cant get anything to work correctly.):

VBA Code:
Dim cP As Range
    For Each cP In Range(Cells(1, 14), Cells(1, hCol)).SpecialCells(xlCellTypeVisible)

        If cP("N1").Visible = True Then lbl_2.Caption = tm.Range("N1").value Else

Thanks in advance for any help or assistance.
 

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,)

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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