That almost works.
I changed it to a function and called it from my macro that fills the data into the sheet. That worked great, it did exactly what I wanted it to do.
Now the problem is when I clear that sheet and refill it with different data, even if the amount of data is less, it applies borders to every row that was previously used.
Here is the code with my few changes (I made it start at row 2 because I have headers with pre-established formatting):
Function RemoveReapplyBorders()
Dim arrItm
Dim lngRows As Long
With Worksheets("RMS Order").UsedRange
For Each arrItm In Array(xlEdgeTop, xlEdgeBottom, xlEdgeLeft, xlEdgeRight, xlDiagonalDown, xlDiagonalUp, xlInsideVertical, xlInsideHorizontal)
.Borders(arrItm).LineStyle = xlNone
Next arrItm
For lngRows = 2 To .Rows.Count
.Rows(lngRows).Borders(xlEdgeBottom).LineStyle = xlContinuous
Next
End With
End Function
Here is the code I use to clear the sheet:
Function RMSOrderClear()
'Resets the RMS Order Page to the original unused state.
Application.ScreenUpdating = False
Dim arrItm
'Clears the RMS Order page
With ActiveWorkbook.Worksheets("RMS Order")
.Range("A2:D2000").ClearContents
End With
With Worksheets("RMS Order").UsedRange '.Offset(1).Resize(.UsedRange.Rows.Count - 1)
For Each arrItm In Array(xlEdgeTop, xlEdgeBottom, xlEdgeLeft, xlEdgeRight, xlDiagonalDown, xlDiagonalUp, xlInsideVertical, xlInsideHorizontal)
.Borders(arrItm).LineStyle = xlNone 'remove all existing borders in used range
Next arrItm
End With
Application.ScreenUpdating = True
End Function
I clear the contents on rows "A2:2000" because those are the only columns used, and we don't even have 2000 parts that could possibly be ordered, so there is no way the total will surpass that.
I originally tried applying this code to clear it:
Function RMSOrderClear()
'Resets the RMS Order Page to the original unused state.
Application.ScreenUpdating = False
Dim arrItm
'Clears the RMS Order page
With ActiveWorkbook.Worksheets("RMS Order")
.Range("A2:D2000").ClearContents
.Range("A2:D2000").Borders.LineStyle = xlNone
End With
Application.ScreenUpdating = True
End Function
But then when I ran the code to fill the sheet again, it put a border on every row from 2 to 2000.
I cleared that by applying the first clear code, but then every time I ran the code again, it would refill the 1999 rows with borders. The only way I could get it to stop that was to delete all 1999 rows.
Then when I ran the code, it worked. But when I changed the amount of data into the sheet to fewer rows, it still applied the borders to the previously used rows.
Even though there is nothing else ever on this page, and the only print area that is established is to control the vertical so it prints all 4 columns on one page. I do not want to have the macro delete the rows, if I can avoid that.