+ Reply to Thread
Results 1 to 5 of 5

Excel 2007 : Is there an easier way to write the attached code:

Hybrid View

  1. #1
    Registered User
    Join Date
    03-11-2011
    Location
    Dublin
    MS-Off Ver
    Excel 2007
    Posts
    17

    Is there an easier way to write the attached code:

    Hi,
    I'm currently putting together a a user form that sets the toggle buttons within the form as true depending on what cell has called it.The issue I have is that there are 256 combinations, is there an easier way to write the code for this other than what I have, example below (16 Days by 16 Types).Writing it the way I have started would mean 256 'End If' statements at the end of the coding.
    Any help welcome

    HTML Code: 
    Thanks in Advance
    Spagbog
    Last edited by Spagbog; 01-19-2012 at 05:30 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Is there an easier way to write the attached code:

    Maybe you could throw some more light on what you are trying to accomplish through these IF loops. You could explain what you are trying to compare / validate using the code, then we can help you much faster.

    Also, it will be good if you attach your sample workbook.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Is there an easier way to write the attached code:

    If they all follow that naming convention then you can use:
    Me.Controls(Replace(Replace(Activecell.Value, "Activation", ""), " ", "")).Value = True
    Me.Controls(Replace(Activecell.Offset(0, 3).Value, " ", "")).Value = True
    Good luck.

  4. #4
    Registered User
    Join Date
    03-11-2011
    Location
    Dublin
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Is there an easier way to write the attached code:

    Thanks for looking Guys,the Me.solution works fine for the lines with Activation, there are also the same number of lines with Conjugation can this code be modified to suit both?
    Sorry for not getting back sooner
    Thanks in advance

  5. #5
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Is there an easier way to write the attached code:

    It sounds as though you can simply repeat the lines
    Me.Controls(Replace(Replace(Activecell.Value, "Activation", ""), " ", "")).Value = True
    Me.Controls(Replace(Activecell.Offset(0, 3).Value, " ", "")).Value = True
    Me.Controls(Replace(Replace(Activecell.Value, "Conjugation", ""), " ", "")).Value = True
    Me.Controls(Replace(Activecell.Offset(0, 3).Value, " ", "")).Value = True

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1