Results 1 to 8 of 8

Thread: [RESOLVED] Chang caption of checkbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Resolved [RESOLVED] Chang caption of checkbox

    Hello,

    I was wondering if it is possible that the caption of a checkbox can be changed in a loop.

    The problem is that i have 12 checkboxes on a form. These checkboxes only can be shown at the moment that other cell on a certain sheet "standaard" are filled. In our example i want to create a loop for range B8:B19. The reference cell where the future name of the checkbox.caption is stored is R8:R19.

    Now is there some code that i automaticly can loop the checkbox in reference with the activecell out of range B8:B19
    All the checkboxes have the name Chk1, ..2, ..3, until 12
    In the future there will be manymore checkboxes added, so for the code it's much easier when it's short and understandable then copy paste these lines over and over.

    The code i have is as follows and is be done in de initilize routine.

    Code:
        1:  Set std = Worksheets("standaard")
        2:  std.Visible = xlSheetVisible
        3:  std.Select
        4:  Range("b8:b19").Select
        5:  ActiveCell.Offset(0, 0).Select
        6:  For I = 1 To 12
        7:  If ActiveCell <> "" Then
        8:  ActiveCell.Offset(0, 16).Select
        9:  Chk1.Caption = ActiveCell.Value
        10: Chk1.Enabled = True
        11: ActiveCell.Offset(1, -16).Select
        12: Else
        13: Chk1.Caption = ""
        14: Chk1.Enabled = False
        15: ActiveCell.Offset(1, 0).Select
        16: End If
        17: Next

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Chang caption of checkbox

    First create a checkbox. Then copy it and paste to create a control array.
    Then you can use your code like this....
    Code:
    Set std = Worksheets("standaard")
        2:  std.Visible = xlSheetVisible
        3:  std.Select
        4:  Range("b8:b19").Select
        5:  ActiveCell.Offset(0, 0).Select
        6:  For I = 1 To 12
        7:  If ActiveCell <> "" Then
        8:  ActiveCell.Offset(0, 16).Select
        9:  Chk1(I).Caption = ActiveCell.Value 'changed
        10: Chk1(I).Enabled = True 'changed
        11: ActiveCell.Offset(1, -16).Select
        12: Else
        13: Chk1(I).Caption = "" 'changed
        14: Chk1(I).Enabled = False 'changed
        15: ActiveCell.Offset(1, 0).Select
        16: End If
        17: Next

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Chang caption of checkbox

    BTW... Welcome to VBForums

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Chang caption of checkbox

    Moved to Office Development

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Re: Chang caption of checkbox

    Thanks, but i'm new with vba. I got a goal to make an excell sheet more users friendly. I want to accomplish my goal and maybe i'll get a good change to follow a cursus of VBA for office. It's quit expensive here and i want the company to pay for it.

    Can you help m e further with a control array..

    Thx

  6. #6
    Addicted Member
    Join Date
    Jul 2008
    Location
    Colorado
    Posts
    193

    Re: Chang caption of checkbox

    VBA does not support control arrays.

    Assuming that your checkboxes are on a form, you could do the following:
    vb Code:
    1. Dim TempName as string
    2. For i = 1 to 12
    3.    TempName = "Chk" & i
    4.    If ActiveCell <> "" Then
    5.       ActiveCell.Offset(0, 16).Select
    6.       Me.Controls(TempName).Caption = ActiveCell.Value
    7.       Me.Controls(TempName).Enabled = True
    8.    Else
    9.       'More code
    10.    End If
    11. Next

    This works for code on a form, where the checkboxes are on the form. ("Me" refers to the form)

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    Re: Chang caption of checkbox

    It works fine, thx all.

  8. #8
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Chang caption of checkbox

    If your problem is solved, then mark the thread as RESOLVED...
    And if you find someone's post as helpful, then try to rate him...

    -Best wishes

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

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



Click Here to Expand Forum to Full Width