Results 1 to 2 of 2

Thread: Label Caption based on Active Cell value

  1. #1
    Member
    Join Date
    Jul 2013
    Posts
    40
    Rep Power
    0

    Label Caption based on Active Cell value

    I have a workbook with a sheet "Data" that has a table with 7 columns of data and 1001 rows. One of the columns contains a 4digit unique number, also the 1st line contains the table headers.
    I have made a userform (with a Textbox and 6 Labels) so as to make the data of each line appear.
    The concept is simple, type the 4digit unique number in "IdNo" Textbox, press "Find" Commandbutton, all 6 Labels captions are updated.

    So I thought that something like the following would do the job...

    Code:
    Private Sub Find_Click()
    Worksheets("Data").Select
    Range("A1:A1002").Find(Me.IdNo.Text).Select
    
    for i=1 to 6
    Me.Controls("Label"&i).Caption = ThisWorkbook.ActiveSheet.ActiveCell.Offset(0, i)
    next i
    End Sub
    Apparently the code is not correct (since I am asking :P). My guess is thatmost likely I'm not defining properly the range...

    I have searched for giving a label its caption based on cells contents but I only found answers pointing to a specific cell. i.e.
    Code:
    Me.Label1.Caption=ThisWorkbook.Sheets("Data").Range("A1")
    No answers based on activecell or activecell offset value....

    Any help would be appreciated....


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=zHJPliWS9FQ&lc=Ugz39PGfytiMUCmTPTl4AaABAg. 91d_Pbzklsp9zfGbIr8hgW
    https://www.youtube.com/watch?v=zHJPliWS9FQ&lc=UgwbcybM8fXnaIK-Y3B4AaABAg.97WIeYeaIeh9zfsJvc21iq
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg. 9zaUSUoUUYs9zciSZa959d
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg. 9zaUSUoUUYs9zckCo1tvPO
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgwMsgdKKlhr2YPpxXl4AaABAg
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwTUdEgR4bdt6crKXF4AaABAg. 9xmkXGSciKJ9xonTti2sIx
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwWw16qBFX39JCRRm54AaABAg. 9xnskBhPnmb9xoq3mGxu_b
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9xon1p2ImxO
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgybZfNJd3l4FokX3cV4AaABAg. 9xm_ufqOILb9xooIlv5PLY
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9y38bzbSqaG
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgyWm8nL7syjhiHtpBF4AaABAg. 9xmt8i0IsEr9y3FT9Y9FeM
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg. 9xhyRrsUUOM9xpn-GDkL3o
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=UgzlC5LBazG6SMDP4nl4AaABAg
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=UgzlC5LBazG6SMDP4nl4AaABAg. 9zYoeePv8sZ9zYqog9KZ5B
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg. 9xhyRrsUUOM9zYlZPKdOpm
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 02-24-2024 at 07:39 PM.
    Keep in mind all vba I know has been googled...

  2. #2
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Code:
    Private Sub Find_Click()
    
        sn = Sheets("Data").Cells(1).CurrentRegion
        x = WorksheetFunction.Match(CInt(Me.IdNo.Text), Sheets("Data").Columns(1), 0)
        For i = 1 To 6
            Me.Controls("Label" & i).Caption = WorksheetFunction.Index(sn, x, i + 1)
        Next i
        
    End Sub

Similar Threads

  1. Inserting Image In VBA User Form Caption
    By littleiitin in forum Download Center
    Replies: 3
    Last Post: 02-22-2021, 03:07 PM
  2. Replies: 2
    Last Post: 05-30-2013, 07:28 PM
  3. Highlight Active Cell’s Row and Column
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 05-17-2013, 12:32 AM
  4. Replies: 15
    Last Post: 05-13-2013, 10:24 PM
  5. Replies: 8
    Last Post: 04-16-2013, 02:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •