Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to preserve border format on range.insert

Tags:

excel

vba

Is there a way to insert a new row while preserving the border format? I am able to insert while preserving all formatting except for borders. The macro that I am creating will essentially prompt the user for a value (strXX) then search for it in a list. If it does not exist, the following is executed.

iRow = WorksheetFunction.Match(strXX, Columns("A")) + 1
Intersect(Range("Z:TT"), Rows(iRow)).Insert _
XlInsertShiftDirection.xlShiftDown, CopyOrigin:=Excel.XlInsertFormatOrigin.xlFormatFromLeftOrAbove

Is there something that I must change with respect to the CopyOrigin? There appears to be methods available via the Paste functions, however I am not able to find a similar method when using .Insert.

Any assistance is greatly appreciated...Thanks!

Updated (8/15): Since this post, I have reformatted things in my spreadsheet and am able to work around the issue. I am still very much interested in feedback as the original configuration was not able to copy the border. This will surely resurface at a later date. Please see below for supporting info.

There are 2 sheets that will be updated. The 1st works well as it preserves the cell formatting (no border required). See below. enter image description here

The issue described in this posting relates to the second sheet. The row is inserted and all formatting is preserved except for the borders (standard "Outside Borders" setting). See below. enter image description here

like image 692
Lazyeye Avatar asked Nov 12 '22 23:11

Lazyeye


1 Answers

Just do it with code as suggested in the comments, something like this

With cell.Borders(xlEdgeTop)
   .LineStyle = xlContinuous
   .ColorIndex = 0
   .TintAndShade = 0
   .Weight = xlThin
End With
With cell.Borders(xlEdgeBottom)
   .LineStyle = xlContinuous
   .ColorIndex = 0
   .TintAndShade = 0
   .Weight = xlThin
End With
With cell.Borders(xlEdgeRight)
   .LineStyle = xlContinuous
   .ColorIndex = 0
   .TintAndShade = 0
   .Weight = xlThin
End With
With cell.Borders(xlEdgeLeft)
   .LineStyle = xlContinuous
   .ColorIndex = 0
   .TintAndShade = 0
   .Weight = xlThin
End With
like image 121
AndrewT Avatar answered Nov 15 '22 07:11

AndrewT