+ Reply to Thread
Results 1 to 4 of 4

Shading cells with If statements

Hybrid View

Guest Shading cells with If... 02-05-2006, 03:54 AM
Guest Re: Shading cells with If... 02-05-2006, 08:45 AM
Guest Re: Shading cells with If... 02-05-2006, 12:10 PM
Guest RE: Shading cells with If... 02-05-2006, 09:00 AM
  1. #1
    haifa
    Guest

    Shading cells with If statements

    Does anyone know how I can shade certain cells in by typing in a letter or
    number, using If statements?

  2. #2
    Peter T
    Guest

    Re: Shading cells with If statements

    Try following in the worksheet module (right-click sheet tab > view code)

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim idx As Long

    On Error GoTo errH
    If Right$(Target(1), 2) = "##" Then
    idx = Val(Target(1))
    If idx < 1 Or idx > 56 Then idx = xlAutomatic
    Application.EnableEvents = False
    Target(1).Interior.ColorIndex = idx

    Target(1).ClearContents
    End If

    errH:
    Application.EnableEvents = True
    End Sub

    Record a macro while formating cells with your favourite colours to get
    colorindex's.

    Type in your colorindex followed by "##". To clear colour format simply type
    "##". (Obviously you could amend "##")

    If you want this to work on all sheets, put similar code in the
    "ThisWorkbook" module but you need to change the event as follows -

    Private Sub Workbook_SheetChange(ByVal Sh As Object, _
    ByVal Target As Range)

    'code

    End Sub

    Regards,
    Peter T

    "haifa" <haifa@discussions.microsoft.com> wrote in message
    news:4EAF000F-3713-41F8-A050-CC19866FF0BA@microsoft.com...
    > Does anyone know how I can shade certain cells in by typing in a letter or
    > number, using If statements?




  3. #3
    Peter T
    Guest

    Re: Shading cells with If statements

    change

    > If idx < 1 Or idx > 56 Then idx = xlAutomatic


    to
    If idx < 1 Or idx > 56 Then idx = xlNone

    Peter T

    "Peter T" <peter_t@discussions> wrote in message
    news:uPKWBHlKGHA.2808@TK2MSFTNGP15.phx.gbl...
    > Try following in the worksheet module (right-click sheet tab > view code)
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim idx As Long
    >
    > On Error GoTo errH
    > If Right$(Target(1), 2) = "##" Then
    > idx = Val(Target(1))
    > If idx < 1 Or idx > 56 Then idx = xlAutomatic
    > Application.EnableEvents = False
    > Target(1).Interior.ColorIndex = idx
    >
    > Target(1).ClearContents
    > End If
    >
    > errH:
    > Application.EnableEvents = True
    > End Sub
    >
    > Record a macro while formating cells with your favourite colours to get
    > colorindex's.
    >
    > Type in your colorindex followed by "##". To clear colour format simply

    type
    > "##". (Obviously you could amend "##")
    >
    > If you want this to work on all sheets, put similar code in the
    > "ThisWorkbook" module but you need to change the event as follows -
    >
    > Private Sub Workbook_SheetChange(ByVal Sh As Object, _
    > ByVal Target As Range)
    >
    > 'code
    >
    > End Sub
    >
    > Regards,
    > Peter T
    >
    > "haifa" <haifa@discussions.microsoft.com> wrote in message
    > news:4EAF000F-3713-41F8-A050-CC19866FF0BA@microsoft.com...
    > > Does anyone know how I can shade certain cells in by typing in a letter

    or
    > > number, using If statements?

    >
    >




  4. #4
    Arnold Reedy
    Guest

    RE: Shading cells with If statements

    Why don't you just use the
    * Menu - Format - Conditional Formatting and
    * set "Cell value is" "equal" "A"
    * Hit the format button and choose whatever text/cell formatting you want

    "haifa" wrote:

    > Does anyone know how I can shade certain cells in by typing in a letter or
    > number, using If statements?


+ 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