Results 1 to 6 of 6

Thread: Help with VBA for background color in selected cells.

  1. #1
    New Member
    Join Date
    Sep 2012
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help with VBA for background color in selected cells.

    Hello,
    I am using the code posted below to remove the center border from an already selected group of cells. It works perfectly, but it then also removes the white background color in the selected cells. I have tried several different codes that I found online (ie cell.interior.color =, .Interior.ColorIndex =) to add to my current code with no luck. I can't define any specific area or range since the groupings can appear anywhere on my worksheet. Any suggestions?
    Thanks



    --------------------------------------------------------------------------------------------------------------------------
    Sub CutMidBorder()
    '
    ' CutMidBorder Macro
    '

    '

    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With

    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone


    End Sub

  2. #2
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,976
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: Help with VBA for background color in selected cells.

    There is nothing in that code that modifies the background colour of the selected cells, and it certainly does not remove the white background that was in my test cells before running your code.

    BTW, I think this shorter macro should do what yours does with the borders.

    Code:
    Sub Fix_Borders()
      With Selection
        .Borders.LineStyle = xlNone
        .BorderAround xlContinuous
      End With
    End Sub
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

  3. #3
    New Member
    Join Date
    Sep 2012
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Re: Help with VBA for background color in selected cells.

    Quote Originally Posted by Peter_SSs View Post
    There is nothing in that code that modifies the background colour of the selected cells, and it certainly does not remove the white background that was in my test cells before running your code.

    BTW, I think this shorter macro should do what yours does with the borders.

    Code:
    Sub Fix_Borders()
      With Selection
        .Borders.LineStyle = xlNone
        .BorderAround xlContinuous
      End With
    End Sub
    Thanks for your reply Peter. Your code also removes the white background on my system. I appreciate your time creating new shorter code for me. Thanks.

  4. #4
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,976
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: Help with VBA for background color in selected cells.

    Quote Originally Posted by onarollcanada View Post
    Your code also removes the white background on my system.
    There is nothing in the code that relates to background colour. There must be something else going on if it is disappearing.

    What is your "system"? What Excel version? What operating system?

    Can you upload a sample dummy file that has the borders and white background to a site (eg DropBox, Box, OneDrive) that we can download from to see what is happening?
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

  5. #5
    New Member
    Join Date
    Sep 2012
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help with VBA for background color in selected cells.

    Quote Originally Posted by Peter_SSs View Post
    There is nothing in the code that relates to background colour. There must be something else going on if it is disappearing.

    What is your "system"? What Excel version? What operating system?

    Can you upload a sample dummy file that has the borders and white background to a site (eg DropBox, Box, OneDrive) that we can download from to see what is happening?
    Hi Peter,
    I started a fresh spreadsheet and used your code. It works perfectly Thank you for your help.
    Cheers

  6. #6
    MrExcel MVP
    Moderator
    Peter_SSs's Avatar
    Join Date
    May 2005
    Location
    Macksville, Australia
    Posts
    40,976
    Post Thanks / Like
    Mentioned
    90 Post(s)
    Tagged
    21 Thread(s)

    Default Re: Help with VBA for background color in selected cells.

    Quote Originally Posted by onarollcanada View Post
    Hi Peter,
    I started a fresh spreadsheet and used your code. It works perfectly Thank you for your help.
    Cheers
    Good idea to try a fresh start! You're welcome.
    Hope this helps, good luck.
    Peter
    Excel 365 - Windows 10
    - Want to help your helpers by posting a small, copyable, screen shot directly in your post? Look here
    - If posting vba code, please use Code Tags - like this [code]Paste code here[/code] - or use the # key in the Reply window
    - Read: Forum Rules, Forum Use Guidelines, & FAQ

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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