Help with VBA for background color in selected cells.

onarollcanada

New Member
Joined
Sep 24, 2012
Messages
11
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

excelbkg.png


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

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,239
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top