Series of labels to correspond to a series of cells

chiabgigi

New Member
Joined
Aug 30, 2009
Messages
48
Hi everyone
I would like a series of labels to correspond to a series of cells
In a Form, arranged vertically, I have 7 series of 15 labels (eg. LblData1, lblData2 etc.)

So lblData1 = BA2, lblCod1 = BB2, lblPag1 = BC2, lblCmp1 = BD2, lblArt1 = BE2, lblQta1 = BL2, lblSub1 = BS2

so far I have only managed to display the first line correctly (BA2 => BS2)
but not the others below
(BA3 => BS3), (BA4 => BS4), etc.

This is the code:
VBA Code:
Dim x, y, w, j, k, x1, y1
Dim LastRow1 As Long
LastRow1 = Sheets("Dati").Cells(Rows.Count, "BA").End(xlUp).Row

For x = 1 To 15
  Me.Controls("lblData" & x).Caption = Range("BA1").Offset(x, 0).Value
    Exit For
  Next x

For y = 1 To 15
  Me.Controls("lblPag" & y).Caption = Range("BC1").Offset(y, 0).Value
    Exit For
  Next y

For w = 1 To 15
  Me.Controls("lblCmp" & w).Caption = Range("BD1").Offset(w, 0).Value
    Exit For
  Next w

For j = 1 To 15
  Me.Controls("lblCod" & j).Caption = Range("BB1").Offset(j, 0).Value
    Exit For
  Next j

For k = 1 To 15
  Me.Controls("lblArt" & k).Caption = Range("BE1").Offset(k, 0).Value
    Exit For
  Next k

For x1 = 1 To 15
  Me.Controls("lblQta" & x1).Caption = Range("BL1").Offset(x1, 0).Value
    Exit For
  Next x1

For y1 = 1 To 15
  Me.Controls("lblSub" & y1).Caption = Range("BS1").Offset(y1, 0).Value
    Exit For
  Next y1

How to also display the entries in Rows 3,4,5, etc.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You can also do that with one loop like
VBA Code:
For x = 1 To 15
   Me.Controls("lblData" & x).Caption = Range("BA1").Offset(x, 0).Value
   Me.Controls("lblPag" & x).Caption = Range("BC1").Offset(x, 0).Value
   Me.Controls("lblCmp" & x).Caption = Range("BD1").Offset(x, 0).Value
Next x
 
Upvote 0
I have now realized that when I change the sheet I lose the data. Is it possible to always have the data from the sheet, even if I move between the other sheets?
 
Upvote 0
You can specify the sheet like this
VBA Code:
With Sheets("Sheets1")
   For x = 1 To 15
      Me.Controls("lblData" & x).Caption = .Range("BA1").Offset(x, 0).Value
      Me.Controls("lblPag" & x).Caption = .Range("BC1").Offset(x, 0).Value
      Me.Controls("lblCmp" & x).Caption = .Range("BD1").Offset(x, 0).Value
   Next x
End With
note that you need the . before the word range.
 
Upvote 0

Forum statistics

Threads
1,215,884
Messages
6,127,563
Members
449,385
Latest member
KMGLarson

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