ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   FORMATTING UNDERLINES AND BORDERS (https://www.excelbanter.com/excel-programming/383074-formatting-underlines-borders.html)

[email protected]

FORMATTING UNDERLINES AND BORDERS
 
I have a spreadsheet of financial information. The line items which
are detail information have a "D" in column a and the subtotals and
totals have a different character such as 3 for a subtotal ot "T" for
a total. This macro inserts a blank line after each subtotal or total
(anything not labeled as a "D").

How can I modify it so it will underline the border at either the last
"D" record or place a line at the top of the cell for the first <
"D" ( a line after "cost" in the simple example below)

D Sales $100
D Cost $50
3 Margin $50

D more expenses $50

Sub InsertRow_A_Chg()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim irow As Long, vcurrent As String, i As Long
'// find last used cell in Column A
irow = Cells(Rows.Count, "A").End(xlUp).Row
'// get value of that cell in Column A (column 1)
vcurrent = Cells(irow, 1).Text
'// rows are inserted by looping from bottom
For i = irow To 2 Step -1
If Cells(i, 1).Text = "" Then
vcurrent = Cells(i - 1, 1)
ElseIf Cells(i, 1).Text < "D" Then
vcurrent = Cells(i, 1).Text
Rows(i + 1).Insert
End If
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub



All times are GMT +1. The time now is 01:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com