Sub or function not defind message

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
I use the following code.
BUt when i run it i see a message sub or function not defind.


I use the same call procedure on another button which works so stumped as to why this is an issue
If i remove the call procedure it works to clear contents but put it back & i see the message again

Rich (BB code):
Private Sub CommandButton1_Click()

Unload InvoiceClearSheetQuestion
Range("G13:G18").ClearContents
Range("L14:L18").ClearContents
Range("G27:L36").ClearContents
Range("G46:G50").ClearContents
MsgBox "ALL CELLS HAVE NOW BEEN CLEARED", vbInformation, "CLEAR ALL CELLS MESSAGE"
Range("G13").Select

Call PasteIfFormulas_Click
ActiveWorkbook.Save

End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
See below please.

On a comman buttons i have this code that does the job

Rich (BB code):
Private Sub PasteIfFormulas_Click()
     Dim ws As Worksheet

     Application.ScreenUpdating = False
     Application.Calculation = xlCalculationManual

     Set ws = Worksheets("INV")

     ws.Range("G14").Formula = "=IFERROR(IF(INDEX(DATABASE!R:R,$H$13)=0,"""",INDEX(DATABASE!R:R,$H$13)),"""")"
     ws.Range("G14").Formula = "=IFERROR(IF(INDEX(DATABASE!R:R,$H$13)=0,"""",INDEX(DATABASE!R:R,$H$13)),"""")"
     ws.Range("G15").Formula = "=IFERROR(IF(INDEX(DATABASE!S:S,$H$13)=0,"""",INDEX(DATABASE!S:S,$H$13)),"""")"
     ws.Range("G16").Formula = "=IFERROR(IF(INDEX(DATABASE!T:T,$H$13)=0,"""",INDEX(DATABASE!T:T,$H$13)),"""")"
     ws.Range("G17").Formula = "=IFERROR(IF(INDEX(DATABASE!U:U,$H$13)=0,"""",INDEX(DATABASE!U:U,$H$13)),"""")"
     ws.Range("G18").Formula = "=IFERROR(IF(INDEX(DATABASE!V:V,$H$13)=0,"""",INDEX(DATABASE!V:V,$H$13)),"""")"
     
     ws.Range("L14").Formula = "=IFERROR(IF(INDEX(DATABASE!D:D,$H$13)=0,"""",INDEX(DATABASE!D:D,$H$13)),"""")"
     ws.Range("L15").Formula = "=IFERROR(IF(INDEX(DATABASE!B:B,$H$13)=0,"""",INDEX(DATABASE!B:B,$H$13)),"""")"
     ws.Range("L16").Formula = "=IFERROR(IF(INDEX(DATABASE!L:L,$H$13)=0,"""",INDEX(DATABASE!L:L,$H$13)),"""")"
     ws.Range("L17").Formula = "=IFERROR(IF(INDEX(DATABASE!W:W,$H$13)=0,"""",INDEX(DATABASE!W:W,$H$13)),"""")"
     
     ws.Range("M27").Formula = "=IF(AND(H27="""",H27=""""),"""",H27*J27)"
     ws.Range("M28").Formula = "=IF(AND(H28="""",H28=""""),"""",H28*J28)"
     ws.Range("M29").Formula = "=IF(AND(H29="""",H29=""""),"""",H29*J29)"
     ws.Range("M30").Formula = "=IF(AND(H30="""",H30=""""),"""",H30*J30)"
     ws.Range("M31").Formula = "=IF(AND(H31="""",H31=""""),"""",H31*J31)"
     ws.Range("M32").Formula = "=IF(AND(H32="""",H32=""""),"""",H32*J32)"
     ws.Range("M33").Formula = "=IF(AND(H33="""",H33=""""),"""",H33*J33)"
     ws.Range("M34").Formula = "=IF(AND(H34="""",H34=""""),"""",H34*J34)"
     ws.Range("M35").Formula = "=IF(AND(H35="""",H35=""""),"""",H35*J35)"
     ws.Range("M36").Formula = "=IF(AND(H36="""",H36=""""),"""",H36*J36)"
     
     Application.Calculation = xlCalculationAutomatic
     Application.ScreenUpdating = True
     
End Sub


Do on the button in question which gives me the error i have this.

Rich (BB code):
Private Sub CommandButton1_Click()
Unload InvoiceClearSheetQuestion
Range("G13:G18").ClearContents
Range("L14:L18").ClearContents
Range("G27:L36").ClearContents
Range("G46:G50").ClearContents
MsgBox "ALL CELLS HAVE NOW BEEN CLEARED", vbInformation, "CLEAR ALL CELLS MESSAGE"
Range("G13").Select

Call PasteIfFormulas_Click
ActiveWorkbook.Save
End Sub
 
Upvote 0
Both are on a worksheet called INV
They clear fields of date / add the IF back in if deleted
 
Upvote 0
Both are on a worksheet called INV
You should share your file from the original post, since you do NOT put the complete information, you are delivering data little by little and something that could be solved in a single post becomes eternal.
 
Upvote 0
Here we go

download here

Worksheet called INV

Click GENERATE PDF
Once done a confirmation message is shown.
Clicking ok opens the file but maybe wont do this for you.
So you should see a userform DO YOU WISH TO CLEAR THE SHEETS DETAILS YS / NO
Select YES
Cells in code ranged are cleared

No the range in the code should have the IF statements entered.
As a test the red command button is the one that works.
So this is where i get the call procedure from
 
Upvote 0
Check that in all the code of your userform you have a procedure with exactly the same name.
First, in all the code of your InvoiceClearSheetQuestion userform, there is no "PasteIfFormulas_Click" procedure.


Make the following changes:

In the code of Sheet14 change this line:
VBA Code:
Private Sub PasteIfFormulas_Click()

By this line:
VBA Code:
Sub PasteIfFormulas_Click()

In the code of InvoiceClearSheetQuestion userform change this line:
VBA Code:
Call PasteIfFormulas_Click

By this line:
VBA Code:
Call Sheet14.PasteIfFormulas_Click
 
Upvote 0
Solution

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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