How do I make my command button work by calling procedures that work
Results 1 to 2 of 2

Thread: How do I make my command button work by calling procedures that work
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Aug 2018
    Location
    NSW, Australia
    Posts
    775
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default How do I make my command button work by calling procedures that work

    I have tried to call my procedures to copy lines and clear cells that work if I run them individually but if I try and click on my red button, "Copy to relevant sheet and clear lines" on the Costing_tool sheet, one of the procedure names is highlighted and the error message reads: Expected procedure, not variable. Can someone help me fix this please?

    I have uploaded my spreadsheet.
    https://www.dropbox.com/s/s5s5f900zv...13.9.xlsm?dl=0

    Thanks,
    Dave

  2. #2
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling, Scotland
    Posts
    75,108
    Post Thanks / Like
    Mentioned
    60 Post(s)
    Tagged
    6 Thread(s)

    Default Re: How do I make my command button work by calling procedures that work

    Dave

    cmdDeleteAll actually refers to the button, if you want to call the buttons Click event try this.
    Code:
        Call cmdDeleteAll_Click
    Mind you I wouldn't recommend calling an event like that, instead you could put the code for the Click event in a separate sub and that could be called from elsewhere.

    For example if you created this sub in Module1,
    Code:
    Sub DeleteAll()
    'Deleting The Data In A Table
    Dim tbl As ListObject
    Dim cell As Range
    
        Set tbl = ThisWorkbook.Sheets("Costing_tool").ListObjects("tblCosting")
        'Delete all table rows except first row
        With tbl.DataBodyRange
            If .Rows.Count > 1 Then
                .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).Rows.Delete
            End If
            'Clear the contents, but not delete the formulas
            For Each cell In tbl.ListRows(1).Range.Cells
                If Not cell.HasFormula Then
                    cell.Value = ""
                End If
            Next
        End With
        
    End Sub
    you could then have this for the Click event of the button,
    Code:
    Sub cmdDeleteAll_Click()
        Call DeleteAll
    End Sub
    and for the 'Copy to relevant sheet and clear lines' button you could have this.
    Code:
    Sub cmdCopyLineBlank_Click()
    
        Call cmdCopy
    
        Call DeleteAll
    
        Worksheets("Costing_tool").Unprotect Password:="costings"
        'Worksheets("Costing_tool").Protect Password:="costings"
    End Sub
    Last edited by Norie; Jun 14th, 2019 at 12:11 AM.
    If posting code please use code tags.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •