Results 1 to 5 of 5

Thread: Conditional Formatting - multples from vba

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Conditional Formatting - multples from vba

    Mornin all. ;0

    I have a range of cells and a variety of conditions that I'm trying to create.

    Specifically, if a number is below a range, do nothing, if it's within a range, I need to to change the font and color, and if it exceeds a range, I need it to change font and color yet again. (bold/orange and bold/red respectivly)

    and I need to do this 22 times, once per row in range j627

    I tried various combinations (wish I'd saved the code) but all I could get was an effect that turned everything black.

    Can someone please help me with this?

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Conditional Formatting - multples from vba

    Code:
    rng.interior.colorindex=??
    Record macros, experiment... thats the background

    Code:
    rng.font.colorindex = ?? 'guessing
    I think this is the font colour - you can check with a recording macro.


    If you want you should be able to set conditional formating for the ranges though.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: Conditional Formatting - multples from vba

    my fault for not clarifying, it's the code itself I need. I don't know how to code this in excel. I can record a macro but it acts like a drone, doing the same thing over and over again, regardless of the cell contents.

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Conditional Formatting - multples from vba

    this will trigger on selection change....

    put the code in "ThisWorkbook"
    then change the numbers to what u want to test for

    VB Code:
    1. Dim WithEvents CWS As Worksheet
    2.  
    3. Private Sub CWS_SelectionChange(ByVal Target As Range)
    4.    
    5.     For x = 10 To 16
    6.         For I = 6 To 27
    7.                 If CWS.Cells(I, x) >= 10 And CWS.Cells(I, x) <= 25 Then
    8.                     CWS.Cells(I, x).Interior.ColorIndex = 46
    9.                     CWS.Cells(I, x).Font.Bold = True
    10.                 ElseIf CWS.Cells(I, x) > 25 Then
    11.                     CWS.Cells(I, x).Interior.ColorIndex = 3
    12.                     CWS.Cells(I, x).Font.Bold = True
    13.                    
    14.                 End If
    15.         Next
    16.     Next
    17.    
    18.    
    19. End Sub
    20.  
    21. Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    22.     Set CWS = Sh
    23. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Conditional Formatting - multples from vba

    Alba:
    sorry Yeah you need to use the code but reformat it to do what you want.
    I usually do this by changing the selection object to proper objects and using a start position.

    For example:
    Create this code, create a toolbar button that runs the macro.
    Click various cells and then the toolbar button.
    Code:
    Public Sub tellme()
        Dim wrk As Workbook
        Dim sht As Worksheet
        Dim rng As Range
    
        Set wrk = Application.Workbooks(1)
        Set sht = wrk.Sheets(1)
        Set rng = ActiveCell
        
        MsgBox "The Address is " & rng.Address(False, False)
        
        Set rng = Nothing
        Set sht = Nothing
        Set wrk = Nothing
    End Sub
    The rest is experimenting and getting used to Excels objects

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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