+ Reply to Thread
Results 1 to 9 of 9

How do you change cell border line and color specs using VBA?

  1. #1
    Registered User
    Join Date
    10-10-2003
    Posts
    31

    How do you change cell border line and color specs using VBA?

    I have this simple VBA which paints the cell backgrounds for the whole row and column in which a cell exists a bright yellow.

    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Cells.Interior.ColorIndex = xlNone
    With ActiveCell
    .EntireRow.Interior.ColorIndex = 36
    .EntireColumn.Interior.ColorIndex = 36
    End With
    End Sub

    I would like, instead, to paint the TOP and BOTTOM borders of the cells in the ROW a bright medium-width blue, and the LEFT-side and RIGHT-side borders of the cells in the COLUMN the same way. I'm not sure how to craft the two statements ("EntireRow..." and "EntireColumn...") in the code to accomplish that. Help appreciated. Thanks.

    - Jim

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: How do you change cell border line and color specs using VBA?

    Your best bet is to figure out how to do it manually (or if you already know, great), then, turn on the macro recorder to get the objects and colors and border specs....just a thought
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,816

    Re: How do you change cell border line and color specs using VBA?

    Hi Jim. Try:
    Please Login or Register  to view this content.
    Last edited by Mumps1; 11-08-2013 at 04:06 PM.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,876

    Re: How do you change cell border line and color specs using VBA?

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    10-10-2003
    Posts
    31

    Re: How do you change cell border line and color specs using VBA?

    Judgeh59 - Idiot! ...not you, me. Sometimes I get so close to this stuff I don't see the easy path every 'Introduction to Excel' high school student is familiar with. Thanks for the reality check.

    Mumps1 - thanks, you've provided the answer I was expecting to get. Just one issue: I can't live with "Cells.Interior.ColorIndex = xlNone" because (I assume) it will wipe out all of the cell SHADINGS we use for various highlighting purposes. I need a version of the statement that only wipes out the border settings and leaves the cell background colors alone. Can do?

  6. #6
    Registered User
    Join Date
    10-10-2003
    Posts
    31

    Re: How do you change cell border line and color specs using VBA?

    Alan - Not sure who you are/were talking to and whether I should do something (or perhaps Mumps1) to get us down the road. Please advise (sorry about the rules violation). - Jim

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,876

    Re: How do you change cell border line and color specs using VBA?

    Jim, You will need to fix your thread as it does not contain the required code tags.

    In the first post, click on edit, highlight the vba code and click on the #. Then save it.

    Alan

  8. #8
    Registered User
    Join Date
    10-10-2003
    Posts
    31

    Re: How do you change cell border line and color specs using VBA?

    Thanks Mumps!. Alan, I transitioned my first post to edit mode and highlighted my code but I could not find a "#" to click. - Jim

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,876

    Re: How do you change cell border line and color specs using VBA?

    It is in the icon bar just above the message window. On the same line you would use to format the text.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to change cell border colors from one color to another
    By Hanskubansku in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2012, 07:41 AM
  2. How do I keep color and border line formatting
    By iwannabenobody in forum Excel General
    Replies: 7
    Last Post: 07-26-2012, 02:49 AM
  3. Change a cell's formatting, like 25% gray fill or L,R,T,B border color ???
    By BaLLZaCH in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-27-2009, 05:19 PM
  4. [SOLVED] How do I change the format/cell/border/automatic color to black
    By tanya in forum Excel General
    Replies: 1
    Last Post: 03-06-2006, 04:10 PM
  5. Replies: 3
    Last Post: 11-02-2005, 07:55 PM

Tags for this Thread

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