+ Reply to Thread
Results 1 to 8 of 8

Simplifying the code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229

    Simplifying the code

    is there another way to shorten this code?

    thanks

    Sub ColorSelection()
    
        If UserForm1.DesignBestEcImage1.Enabled = True Then
            UserForm2.Show
        End If
    
        If UserForm2.Image1.Enabled = True Then
                UserForm1.DesignBestEcImage1.BackColor = &H0&
        End If
          
        If UserForm2.Image2.Enabled = True Then
                UserForm1.DesignBestEcImage1.BackColor = &H80&
        End If
            
        If UserForm2.Image3.Enabled = True Then
                UserForm1.DesignBestEcImage1.BackColor = &HFF&
        End If
        
        If UserForm2.Image4.Enabled = True Then
                UserForm1.DesignBestEcImage1.BackColor = &HFF00FF
        End If
        
        If UserForm2.Image5.Enabled = True Then
                UserForm1.DesignBestEcImage1.BackColor = &HCC99FF
        End If
        
        If UserForm2.Image6.Enabled = True Then
                UserForm1.DesignBestEcImage1.BackColor = &HCC99FF
        End If
        
        If UserForm2.Image7.Enabled = True Then
                UserForm1.DesignBestEcImage1.BackColor = &H800000
        End If
    
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Walid66,

    Here is one version...
    Sub ColorSelection()
    
      Dim BC As Long
      Dim Ctl As Object
      Dim I As Integer
    
        If UserForm1.DesignBestEcImage1.Enabled = True Then
            UserForm2.Show
        Else
            Exit Sub
        End If
    
          For I = 1 To 7
            Set Ctl = UserForm2.Controls("Image" & Trim(Str(I)))
            If Ctl.Enabled = True Then
              Select Case I
                Case 1
                  BC = &H0&
                Case 2
                  BC = &H80& 
                Case 3
                  BC = &HFF&
                Case 4
                  BC = = &HFF00FF
                Case 5, 6
                  BC = &HCC99FF
                Case 7
                  BC = &H800000
              End Select
              UserForm1.DesignBestEcImage1.BackColor = BC
           End If
        Next I
    
    End Sub

  3. #3
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229
    Ok now I have problem selecting different color other than te black color, the script works only on the black color (see attached file). when I start the userform1 and click on the green square top left under the first tab the second userform2 appears and I select the black color the green button changes to black. If I pick different color it stays black. I am not sure where the goes getting stuck. The excel file is 845kb and little big to attach it.
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Walid66,

    Can you attach your workbook? The images aren't helping me to understand your problem.

    Thanks,
    Leith Ross

  5. #5
    Forum Contributor
    Join Date
    12-09-2006
    Posts
    229
    the file is over the limit which 845 kb is there other way I can send it to you beside uploading.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Walid66,

    You can email me at LeithRoss@gmail.com.

    Sincerely,
    Leith Ross

+ 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