+ Reply to Thread
Results 1 to 2 of 2

simple: type mismatch

  1. #1
    mark kubicki
    Guest

    simple: type mismatch

    feel like an idiot that i can't get this one right... never-the-less...

    B3:B10 have no special format, and could either have text, or be null

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, ActiveSheet.Range("B3:B10")) Is Nothing Then
    If Len(trim(Range(Target.Address).Value) )= 0 Then
    Target.Interior.ColorIndex = 53
    Else
    Target.Interior.ColorIndex = 36
    End If
    End If
    End Sub

    run time error 13
    type mismatch

    thanks in advance,
    mark



  2. #2
    Chris Marlow
    Guest

    RE: simple: type mismatch

    Mark,

    Not sure exactly what you are trying to do, but;

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim ranRange As Range

    For Each ranRange In Target.Cells

    If Not Intersect(ranRange, ActiveSheet.Range("B3:B10")) Is Nothing
    Then
    If Len(Trim(Range(ranRange.Address).Value)) = 0 Then
    Target.Interior.ColorIndex = 53
    Else
    Target.Interior.ColorIndex = 36
    End If
    End If

    Next ranRange

    End Sub

    Gives no error ... the important bit I guess is that when you do the 'Trim'
    the range is one cell (which the for each ensures).

    Regards,

    Chris.

    --
    Chris Marlow
    MCSD.NET, Microsoft Office XP Master


    "mark kubicki" wrote:

    > feel like an idiot that i can't get this one right... never-the-less...
    >
    > B3:B10 have no special format, and could either have text, or be null
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > If Not Intersect(Target, ActiveSheet.Range("B3:B10")) Is Nothing Then
    > If Len(trim(Range(Target.Address).Value) )= 0 Then
    > Target.Interior.ColorIndex = 53
    > Else
    > Target.Interior.ColorIndex = 36
    > End If
    > End If
    > End Sub
    >
    > run time error 13
    > type mismatch
    >
    > thanks in advance,
    > mark
    >
    >
    >


+ 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