Consulting

Results 1 to 9 of 9

Thread: What's the syntax for adding colour?

  1. #1
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location

    What's the syntax for adding colour?

    Hi

    If I try to change this:

    Borders(xlEdgeLeft).LineStyle = xlDouble
    to this:

    Borders(xlEdgeLeft).LineStyle = xlDouble.ColorIndex = 11
    I get told to crawl back under the rock from whence I came.

    How does one add colour to borders if all the border making instruction is all on the same line of code - me no know
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    You don't have it all on the same line.

    With Cells.Borders(xlEdgeLeft)
         .LineStyle = xlDouble
         .ColorIndex = 11
    End With

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Babydum
    Hi

    If I try to change this:

    Borders(xlEdgeLeft).LineStyle = xlDouble

    to this:

    Borders(xlEdgeLeft).LineStyle = xlDouble.ColorIndex = 11

    I get told to crawl back under the rock from whence I came.

    How does one add colour to borders if all the border making instruction is all on the same line of code - me no know
    Oh DummyBabe!

    Didi it not occur to thee that linestyle is a property pertaining to the line style, and that colour is another property.

    Maybe this can help


    With Range("B2").Borders(xlEdgeLeft)
        .LineStyle = xlDouble
        .ColorIndex = 11
    End With
    If you want to set a border around, you can do that all in one command

    With Range("B2")
        .BorderAround xlDouble, xlThick, 11
    End With
    Being serious now, if you are going to wreak havoc with VBA, you should learn to wreak proper havoc. You need to understand the object browser. If you invoke the OB, F2 or the icon on the standard toolbar, you will be presented with a small dialog that gives you access to the Excel and VBA object models (and others). Type your object name in the search box, and you will then be presented with details on that object. You can peruse its properties at leisure then. It might become more obvious.
    ____________________________________________
    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

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by xld
    ..If you want to set a border around, you can do that all in one command

    With Range("B2")
        .BorderAround xlDouble, xlThick, 11
    End With
    Of course if you really only wanted one command, you wouldn't need the With statement, would you..

  5. #5
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Well, this is the problem: There is no "With Selection" thingimmigig in my code for me to play with. I was just trying to save my friend the bother of fixing this for me by attempting to do it myself. But the code is:

    Trainers.Range(Cells(7, i).Address & ":" & Cells(LastRow, i).Address).Borders(xlEdgeRight).LineStyle = xlDouble
    Rooms.Range(Cells(7, i).Address & ":" & Cells(LastRow, i).Address).Borders(xlEdgeRight).LineStyle = xlDouble
    So TLC, when it comes to spreadsheet design I may be a bit Dummy, this I can't deny. But I also come up with ideas for very sexy spreadsheets (which Killian, for one, likes the sound of). One out of two ain't bad.

    Anyhoo, thanks both for your advice, but, as suggested, I'm off to browse my objects. So i'll see you later.
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by firefytr
    Of course if you really only wanted one command, you wouldn't need the With statement, would you..
    You might


    With Worksheets("Sheet1")
        .Range(.Cells(1, 1), .Cells(10, 10)).Value = 99
    End With
    ____________________________________________
    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 Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    So how to I get your suggestions into the code below?
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Babydum
    So how to I get your suggestions into the code below?
    You don't have a selection thingimmigig in there perhaps, but selection is just a range, and you do have a range. If we re-write your code somewhat,

    Trainers.Range(Cells(7, i).Address & ":" & Cells(LastRow, i).Address) _
        .Borders(xlEdgeRight).LineStyle = xlDouble
    Rooms.Range(Cells(7, i).Address & ":" & Cells(LastRow, i).Address) _
        .Borders(xlEdgeRight).LineStyle = xlDouble

    the first of each pair of lines is the range, and Borders is a property of Range (the good ol' OB again). So you can easily implement with

    With Trainers.Range(Cells(7, i).Address & ":" & Cells(LastRow, i).Address)
        With .Borders(xlEdgeRight)
            .LineStyle = xlDouble
            .ColorIndex = 11
        End With
    End With
    With Rooms.Range(Cells(7, i).Address & ":" & Cells(LastRow, i).Address)
         With .Borders(xlEdgeRight)
            .LineStyle = xlDouble
            .ColorIndex = 11
        End With
    End With
    And you can improve the code. These two statements are equivalent

    Trainers.Range (Cells(7, i).Address & ":" & Cells(LastRow, i).Address)
    Trainers.Range(Cells(7, i), Cells(LastRow, i))

    BTW Hope I didn't offend you, just trying to add some levity.

    .
    ____________________________________________
    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

  9. #9
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by xld
    BTW Hope I didn't offend you, just trying to add some levity.
    Of course you didn't offend me!

    Thanks for your help!
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

Posting Permissions

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