+ Reply to Thread
Results 1 to 4 of 4

Worksheet events and a little bit extra code

  1. #1
    tinkerbellsmyhoe
    Guest

    Worksheet events and a little bit extra code

    MAN! This is BS! I am an EE with some coding background and i cant
    figure this out for my life. here is the code that i am using:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column = 6 And Target.Row > 3 And Target.Row < 256 And
    Target.Value = "F" Then
    Worksheets("Test Results").Select
    Worksheets("Test Results").Cells(2, Target.Row + 1).Select


    End If


    If Target.Count > 1 Then Exit Sub
    If Target.Column = 7 And Target.Row > 3 And Target.Row < 256 And
    Target.Value = "F" Then
    Worksheets("Test Results").Select
    Worksheets("Test Results").Cells(13, Target.Row + 1).Select
    End If


    If Target.Count > 1 Then Exit Sub
    If Target.Column = 8 And Target.Row > 3 And Target.Row < 256 And
    Target.Value = "F" Then
    Worksheets("Test Results").Select
    Worksheets("Test Results").Cells(24, Target.Row + 1).Select
    End If


    If Target.Count > 1 Then Exit Sub
    If Target.Column = 9 And Target.Row > 3 And Target.Row < 256 And
    Target.Value = "F" Then
    Worksheets("Test Results").Select
    Worksheets("Test Results").Cells(35, Target.Row + 1).Select
    End If


    If Target.Count > 1 Then Exit Sub
    If Target.Column = 10 And Target.Row > 3 And Target.Row < 256 And
    Target.Value = "F" Then
    Worksheets("Test Results").Select
    Worksheets("Test Results").Cells(46, Target.Row + 1).Select
    End If


    If Target.Count > 1 Then Exit Sub
    If Target.Column = 11 And Target.Row > 3 And Target.Row < 256 And
    Target.Value = "F" Then
    Worksheets("Test Results").Select
    Worksheets("Test Results").Cells(57, Target.Row + 1).Select
    End If


    If Target.Count > 1 Then Exit Sub
    If Target.Column = 12 And Target.Row > 3 And Target.Row < 256 And
    Target.Value = "F" Then
    Worksheets("Test Results").Select
    Worksheets("Test Results").Cells(68, Target.Row + 1).Select
    End If
    If Target.Count > 1 Then Exit Sub
    If Target.Column = 13 And Target.Row > 3 And Target.Row < 256 And
    Target.Value = "F" Then
    Worksheets("Test Results").Select
    Worksheets("Test Results").Cells(77, Target.Row + 1).Select
    End If


    End Sub


    I would like to insert a piece of code into each if statement to change

    the target cell + the next 10 rows in that column to a red font. then
    change the font back to black (or default) after the selection changes.



    i have once again given my best shot and the best i can get (once i get

    passed the runtime errors), is for nothing to happen.


    Thanks yet again!


    Mike C.


  2. #2
    tinkerbellsmyhoe
    Guest

    Re: Worksheet events and a little bit extra code

    bump?


  3. #3
    Tom Ogilvy
    Guest

    Re: Worksheet events and a little bit extra code

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Static OldRange as Range
    Dim rng as Range
    On Error goto ErrHandler
    if not OldRange is Nothing then
    OldRange.Font.ColorIndex = xlAutomatic
    Set OldRange = Nothing
    End if
    If Target.Count > 1 Then Exit Sub

    If Target.Row > 3 And Target.Row < 256 _
    And Target.Value = "F" and _
    Target.Column >= 6 and Target.column <= 13 Then
    set rng = Worksheets("Test Results").Cells( _
    (Target.column - 6) * 11 + 2, Target.Row + 1)
    rng.Resize(10,1).Font.ColorIndex = 3
    set OldRange = rng.Resize(10,1)

    ' Optional
    Application.EnableEvents = False
    Application.Goto OldRange, True
    ' End Optional
    End If

    ErrHandler:
    Application.EnableEvents = True
    if err.Number <> 0 then
    msgbox "Error: " & err.Number & vbNewline & _
    vbNewLine & err.Description
    End if
    End Sub

    possibly.

    --
    Regards,
    Tom Ogilvy

    "tinkerbellsmyhoe" <[email protected]> wrote in message
    news:[email protected]...
    > bump?
    >




  4. #4
    tinkerbellsmyhoe
    Guest

    Re: Worksheet events and a little bit extra code

    Tom,

    i'm confused on this piece:
    (Target.column - 6) * 11 + 2, Target.Row + 1)

    also, if i wanted to add a few more cells to the font change is that
    easily done? the cells i wanted to add are:
    A2, B2, C2 through C10, and D2 through D11.

    I HAVE to get a book on this stuff. this is nothing like C except the
    if then statements. all these cell calls and range calls are the
    pitts. how long have you been doing this? and what tools did you use
    to learn?


+ 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