Thursday, November 10, 2016

Excel Add Blank Rows With Checkbox Or Button

Excel Vba Add Blank Rows

            New blank rows can be added under each row with checkbox and button . Blank rows can be deleted with the deleting button.


Used codes for checkbox :
"Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Call Addrow
Else
Call Clr
End If
End Sub"

Sub Addrow()
Dim a As Byte
Dim c As Integer
[A1].Select
a = 2
c = 0
   While ActiveCell.Value <> ""
      c = c + 2
      ActiveSheet.Rows(c).Insert Shift:=xlDown
      ActiveCell.Offset(a, 0).Select
   Wend
  End Sub

Sub Clr()
On Error Resume Next
Range("A2").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub "

Used codes for buttons:
"Private Sub CommandButton1_Click()
Call Addrow
End Sub

Private Sub CommandButton2_Click()
Call Clr
End Sub "

excel vba add blank rows

No comments:

Post a Comment