Consulting

Results 1 to 8 of 8

Thread: conditional formating.

  1. #1
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location

    conditional formating.

    Hi there. Ive been trying to research vba conditional formating for offsetting cells but having a difficult time finding exactly what I need.

    I have a spreadsheet that is a simple schedule. I've run out of normal conditional formatting based on cell value in excel 2003 (Only 3 available) and need more conditions..

    If in any other row is cell value is as example B6 = "Duty" as example I need B6,B5,C6,C5 surrounding cells to change to blue as example.

    This would be the case for the any cell over the spreadsheet...any help is very much appreciated.

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    post a sample workbook of what you want, i am a little unclear on your request but it is easily doable im sure
    ------------------------------------------------
    Happy Coding my friends

  3. #3
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    down and dirty example..
    Attached Files Attached Files

  4. #4
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [VBA]Sub alex()
    Dim col As Variant
    Dim r, lr As Long
    ActiveWorkbook.Sheets(1).Activate
    col = Array("B", "D", "F", "H", "J", "L", "N")
    lr = Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row
    For i = LBound(col) To UBound(col)
    For r = 3 To lr Step 2

    If Cells(r, col(i)).Text = "duty" Then
    Range(Cells(r, col(i)).Offset(-1, 0), Cells(r, col(i)).Offset(0, 1)).Interior.Color = 15773696
    End If
    Next r
    Next i
    End Sub[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  5. #5
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    ....works awesome, except when I delete "duty" it stays the colour, I need it to go back to white.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)

    On Error GoTo ws_exit

    Application.EnableEvents = False

    With Target

    If .Value = "duty" Then

    .Offset(-1, 0).Resize(2, 2).Interior.Color = 15773696
    ElseIf .Value = "" Then

    .Offset(-1, 0).Resize(2, 2).Interior.ColorIndex = xlColorIndexNone
    End If
    End With

    ws_exit:
    Application.EnableEvents = True
    End Sub[/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    xld yours works to what I need to make the cells back to no color. Where do I find the color index for other colors? Do you have a good link. Thanks again.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]Sub ColorindexList()
    Dim i As Long

    Application.ScreenUpdating = False

    With ActiveWorkbook

    .Worksheets.Add After:=.Worksheets(.Worksheets.Count)
    With ActiveSheet

    .Name = "ColorindexList"
    .Range("A1:B1").Value = Array("Colour", "Colorindex")
    For i = 1 To 56

    .Range("A" & i + 1).Interior.ColorIndex = i
    .Range("B" & i + 1).Value = i
    Next i

    .Columns("B").AutoFit
    End With
    End With

    Application.ScreenUpdating = True
    End Sub[/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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