Forum Discussion

adstristar's avatar
adstristar
Brass Contributor
Aug 31, 2019
Solved

Inserting Rows Automatically

I have created a table and in column A I have the departments and in column B I have item numbers. What i want to be able to do automatically is when I enter an additional number onto column B it ins...
  • Subodh_Tiwari_sktneer's avatar
    Subodh_Tiwari_sktneer
    Sep 01, 2019

    adstristar 

    I have tweaked the code. Please replace the existing code with the following code and let me know if this works as desired now.

     

     

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    On Error GoTo Skip:
    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        Application.EnableEvents = False
        If Target.Offset(0, -1) <> "" Then
            If Target <> "" Then
                Rows(Target.Row + 1).Insert
                Target.Offset(1, -1) = Target.Offset(0, -1)
            Else
                If Application.CountIf(Columns(1), Target.Offset(0, -1).Value) > 1 Then
                    Rows(Target.Row).Delete
                End If
            End If
        End If
    End If
    
    Skip:
    Application.EnableEvents = True
    End Sub

     

     

    If that takes care of your original question, please mark your question as Solved by accepting the Answer.

     

Resources