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

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,375
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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