Consulting

Results 1 to 8 of 8

Thread: Using formatting for criteria

  1. #1

    Cool Using formatting for criteria

    Hi,In cells C5, D5, E5 I have some text which are used to give a score to a piece of work, i.e. C5 = Simple, D5 = Medium and E5 = Complex.The way this currently works is fairly basic, but I'm not sure the users want to change the processes. The user would simply highlight one of the cells to indicate the complexity of the piece of work they are doing. What I am aiming to do is allocate a score based on which cell is highlighted, and put a 1,2 or 3 into cell G5. I'd also like to add in some limitation so that only 1 of the 3 cells can highlighted at any time. So if C5 is highlighted, I then go and highlight E5 and C5 becomes 'unhighlighted'.Any ideas if any of this is possible??
    We're a Kingdom, and we're United!!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Const WS_RANGE As String = "C5:E5"

    On Error GoTo ws_exit:
    Application.EnableEvents = False
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    Select Case .Address
    Case "$C$5": Me.Range("G5").Value = 1
    Case "$D$5": Me.Range("G5").Value = 2
    Case "$E$5": Me.Range("G5").Value = 3
    End Select
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.

  3. #3
    Excellent...many thanks for this.Is there anyway to add the number to G5 when the formatting of the internal colour changes, as opposed to just selecting the cell??
    We're a Kingdom, and we're United!!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    A colour change does not trigger any event, so in short, no.

  5. #5
    Oh well, was worth a try.Thanks for the help though.
    We're a Kingdom, and we're United!!

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by Dowsey1977
    Is there anyway to add the number to G5 when the formatting of the internal colour changes, as opposed to just selecting the cell??
    I don't understand what you're after. What cell is undergoing a colour change, and what is causing it?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Cell C5,D5 and E5 would be the cells that would be highlighted. But I want the ability to only have 1 cell highlighted, i.e. if C5 is highlighted, and then I highlight D5, C5 becomes unhighlighted.Then, dependant on what cell is highlighted, either a 1,2 or 3 is added to G5.
    We're a Kingdom, and we're United!!

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    "Highlight" is a confusing term. If you want to colour a cell, which I'm guessing you are, just say so.
    Add these lines after With Target
    [VBA]
    Range("C5:E5").Interior.ColorIndex = xlNone
    Target.Interior.ColorIndex = 6
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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