excel如果还没有最后一行,则添加空行

时间:2017-03-27 15:22:38

标签: excel vba excel-vba

如何在列A中最后一个使用过的单元格下方添加一个空白行,但如果还没有一行,则只添加一个空行?

  

这就是我正在使用的。

Sub LastRowBlank()
Application.ScreenUpdating = False

Dim sht As Worksheet
Dim LastRow As Long
Dim chkCol As Long

Set sht = Sheet1
chkCol = 1
LastRow = sht.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlNext).Row

    If .Cells(LastRow, chkCol).Text = "" Then 'If last row is blank then do nothing


    Else                                       'If last row is not blank then add blank row

    End If

With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
With .Interior
    Range(LastRow).Borders(xlEdgeTop).LineStyle = xlContinuous
End With
Application.ScreenUpdating = True

End Sub
  

由于

1 个答案:

答案 0 :(得分:1)

据我所知,如果你把它放在' Else'阻止你应该设置。

Listbox2.ClearSelected();
foreach (int ind in Listbox1.SelectedIndices)
{
     Listbox2.SetSelected(ind, true);
}

然后,根据您希望边框显示的方式,您可能还必须

Rows(lastrow+1).EntireRow.Insert