Я создаю код VBA в Excel, чтобы добавить строку и отформатировать ее.
Мне нужно, чтобы значение "i" было переменной (вместо 20, как показано), в зависимости от количества записей в первом столбце моего листа Excel.
Sub NextLine()
'
' AddLine Macro
' Adds Line
Dim i As Integer
i = 20
ActiveCell.Offset(1, 0).Select '1 row down
ActiveWindow.ScrollColumn = 4
ActiveWindow.SmallScroll ToRight:=1
Range("$A$1:$M$" & i).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlHairline
End With
ActiveSheet.PageSetup.PrintArea = "$A$1:$M$" & i
End Sub