+ Reply to Thread
Results 1 to 4 of 4

Trouble Condensing Code

  1. #1
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407

    Question Trouble Condensing Code

    I have the following code that I just know could be condensed, but I can't seem to figure it out. Below is some of the code... the weeks go to 12 and the days always stay at 1 thru 5.

    What it does is put a "1" in the appropriate cell if the check box is true and leaves it blank if it is false. Is there a way to condense this code easily? If not I can live with what I have, but it bugs me.

    CODE:

    If frmWeeks.chkWk1Day1 = True Then
    ActiveCell.Offset(0, 5).Value = "1"
    End If

    If frmWeeks.chkWk1Day2 = True Then
    ActiveCell.Offset(0, 6).Value = "1"
    End If

    If frmWeeks.chkWk1Day3 = True Then
    ActiveCell.Offset(0, 7).Value = "1"
    End If

    If frmWeeks.chkWk1Day4 = True Then
    ActiveCell.Offset(0, 8).Value = "1"
    End If

    If frmWeeks.chkWk1Day5 = True Then
    ActiveCell.Offset(0, 9).Value = "1"
    End If

    If frmWeeks.chkWk2Day1 = True Then
    ActiveCell.Offset(0, 10).Value = "1"
    End If

    If frmWeeks.chkWk2Day2 = True Then
    ActiveCell.Offset(0, 11).Value = "1"
    End If

    etc. etc. ...

  2. #2
    Jim Thomlinson
    Guest

    RE: Trouble Condensing Code

    That code is not too bad but if you really want you could clean it up a tad
    something like this...

    with Activecell
    If frmWeeks.chkWk1Day1 = True Then .Offset(0, 5).Value = "1"
    If frmWeeks.chkWk1Day2 = True Then .Offset(0, 6).Value = "1"
    If frmWeeks.chkWk1Day3 = True Then .Offset(0, 7).Value = "1"
    '... the rest here...
    End with
    That is a little neater and easier to copy and paste...
    --
    HTH...

    Jim Thomlinson


    "Ikaabod" wrote:

    >
    > I have the following code that I just know could be condensed, but I
    > can't seem to figure it out. Below is some of the code... the weeks go
    > to 12 and the days always stay at 1 thru 5.
    >
    > What it does is put a "1" in the appropriate cell if the check box is
    > true and leaves it blank if it is false. Is there a way to condense
    > this code easily? If not I can live with what I have, but it bugs me.
    >
    >
    > CODE:
    >
    > If frmWeeks.chkWk1Day1 = True Then
    > ActiveCell.Offset(0, 5).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk1Day2 = True Then
    > ActiveCell.Offset(0, 6).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk1Day3 = True Then
    > ActiveCell.Offset(0, 7).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk1Day4 = True Then
    > ActiveCell.Offset(0, 8).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk1Day5 = True Then
    > ActiveCell.Offset(0, 9).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk2Day1 = True Then
    > ActiveCell.Offset(0, 10).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk2Day2 = True Then
    > ActiveCell.Offset(0, 11).Value = "1"
    > End If
    >
    > etc. etc. ...
    >
    >
    > --
    > Ikaabod
    > ------------------------------------------------------------------------
    > Ikaabod's Profile: http://www.excelforum.com/member.php...o&userid=33371
    > View this thread: http://www.excelforum.com/showthread...hreadid=531992
    >
    >


  3. #3
    Toppers
    Guest

    RE: Trouble Condensing Code

    Are checkboxes on a Userform?

    "Ikaabod" wrote:

    >
    > I have the following code that I just know could be condensed, but I
    > can't seem to figure it out. Below is some of the code... the weeks go
    > to 12 and the days always stay at 1 thru 5.
    >
    > What it does is put a "1" in the appropriate cell if the check box is
    > true and leaves it blank if it is false. Is there a way to condense
    > this code easily? If not I can live with what I have, but it bugs me.
    >
    >
    > CODE:
    >
    > If frmWeeks.chkWk1Day1 = True Then
    > ActiveCell.Offset(0, 5).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk1Day2 = True Then
    > ActiveCell.Offset(0, 6).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk1Day3 = True Then
    > ActiveCell.Offset(0, 7).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk1Day4 = True Then
    > ActiveCell.Offset(0, 8).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk1Day5 = True Then
    > ActiveCell.Offset(0, 9).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk2Day1 = True Then
    > ActiveCell.Offset(0, 10).Value = "1"
    > End If
    >
    > If frmWeeks.chkWk2Day2 = True Then
    > ActiveCell.Offset(0, 11).Value = "1"
    > End If
    >
    > etc. etc. ...
    >
    >
    > --
    > Ikaabod
    > ------------------------------------------------------------------------
    > Ikaabod's Profile: http://www.excelforum.com/member.php...o&userid=33371
    > View this thread: http://www.excelforum.com/showthread...hreadid=531992
    >
    >


  4. #4
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407

    RE: Trouble Condensing Code

    Yes, they are on a userform.

+ 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