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

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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/s5s5f900zve9y59/quoting tool 13.9.xlsm?dl=0

Thanks,
Dave
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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:
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top