Forum Discussion

Khalid0090's avatar
Khalid0090
Copper Contributor
Aug 15, 2023
Solved

VBA Help

Hello All,   I'm working on a form created by Excel and I want to insert buttons and give them some functionality using VBA. I tried using Macros but I didn't get the result I wanted. This form wil...
  • JKPieterse's avatar
    Aug 15, 2023

    Khalid0090 Have a look at the attached.

    The buttons are tied to this code:

     

    
    Sub AddItem()
        Dim targetCell As Range
        With ActiveSheet
            Set targetCell = .Range("A" & .Rows.Count).End(xlUp).Offset(9)
            targetCell.Offset(-11).Resize(10).EntireRow.Copy
            targetCell.EntireRow.Insert xlDown
            targetCell.Offset(-10, 2).Value = 1 'Sets dropdown to 1, change accordingly
            targetCell.Offset(-10, 2).Select
            Application.CutCopyMode = False 'Clear clipboard
        End With
    End Sub
    
    Sub RemoveItem()
        Dim targetCell As Range
        With ActiveSheet
            Set targetCell = .Range("A" & .Rows.Count).End(xlUp).Offset(9)
            If targetCell.Row > 20 Then
                targetCell.Offset(-11).Resize(10).EntireRow.Delete
            Else
                MsgBox "Cannot delete first entry"
            End If
        End With
    End Sub
    

Resources