Need help with my macro "Sub or function not defined"

Status
Not open for further replies.

pekimo

New Member
Joined
Dec 25, 2017
Messages
5
Hello everyone, first off, Merry Christmas!

Now.. Basically i am trying to make a macro that does many things at once (I am very new to excel and VBA as you will probably tell once you see my code lol.

I want the macro to do all of these things in this order:

1) save the current workbook
2) Unhide the sheet called "next"
3) Unprotect all sheets in the workbook (the password is password)
4) Add + 1 to Range C3 from "summary"
5) I then have to copy and paste (values only) of 3 different ranges to 3 different locations (as you can see in my attempt below)
6) Then i need to clear the contents of a whole bunch of ranges (as you can see in my attempt below)
7) Hide sheet "next" again.
8) Protect all my sheets in the workbook again (the password is password)
9) I then want to SAVE AS to "C:\Users\Spreads\ and name it "Admin" + B3 + C3 as xlsx (As you can see in my attempt below at the bottom)

I tried to run this macro and i get the error "Sub or function not defined", i have no idea what this means :/

Also; I feel like there has to be a quicker and shorter way to write that code, but im just too inexperienced to know how.
If anyone wishes to help me with this it would be greatly appreciated, If you do try to rewrite it, i don't expect you to put all my values in for me,
You can just use a symbol such as # or $ and i can fill them in myself, thankyou very much and Merry Christmas again!


Code:
[/COLOR][COLOR=#333333]Sub SaveNewWeek()[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">
Application.ScreenUpdating = False
ActiveWorkbook.Save
Sheets("Next").Visible = True
Worksheet(“Summary”).Unprotect "password"
Worksheet(“Inventory”).Unprotect "password"
Worksheet(“Orders”).Unprotect "password"
Worksheet(“Purchases”).Unprotect "password"
Range("Summary!C3").Value = Range("Summary!C3").Value + 1
Worksheets("Inventory").Range("E10:E159").Copy
Worksheets("Next").Range("C2").PasteSpecial Paste:=xlPasteValues
Worksheets("Summary").Range("C20:C44").Copy
Worksheets("Next").Range("D2").PasteSpecial Paste:=xlPasteValues
Worksheets("Summary").Range("C14").Copy
Worksheets("Next").Range("A2").PasteSpecial Paste:=xlPasteValues
Range("Orders!B48:Orders!EX78").ClearContents
Range("Purchases!B10:Purchases!EW14").ClearContents
Range("Purchases!B20:Purchases!EW24").ClearContents
Range("Purchases!B31:Purchases!EW35").ClearContents
Range("Purchases!B42:Purchases!EW46").ClearContents
Range("Purchases!B53:Purchases!EW57").ClearContents
Range("Purchases!B64:Purchases!EW68").ClearContents
Range("Purchases!B74:Purchases!EW78").ClearContents
Range("Purchases!B85:Purchases!EW89").ClearContents
Range("Purchases!B96:Purchases!EW100").ClearContents
Range("Purchases!B107:Purchases!EW111").ClearContents
Range("Purchases!B119:Purchases!EW123").ClearContents
Range("Purchases!B129:Purchases!EW133").ClearContents
Range("Purchases!B140:Purchases!EW144").ClearContents
Range("Purchases!B151:Purchases!EW155").ClearContents
Range("Purchases!B162:Purchases!EW166").ClearContents
Range("Purchases!B174:Purchases!EW178").ClearContents
Range("Purchases!B184:Purchases!EW188").ClearContents
Range("Purchases!B195:Purchases!EW199").ClearContents
Range("Purchases!B206:Purchases!EW210").ClearContents
Range("Purchases!B217:Purchases!EW221").ClearContents
Range("Purchases!B229:Purchases!EW233").ClearContents
Range("Purchases!B239:Purchases!EW243").ClearContents
Range("Purchases!B250:Purchases!EW254").ClearContents
Range("Purchases!B261:Purchases!EW265").ClearContents
Range("Purchases!B272:Purchases!EW276").ClearContents
Sheets("Next").Visible = False
Worksheet(“Summary”).Protect "password"
Worksheet(“Inventory”).Protect "password"
Worksheet(“Orders”).Protect "password"
Worksheet(“Purchases”).Protect "password"
ActiveWorkbook.SaveCopyAs "C:\Users\Spreads\Admin" & Range("Summary!B3").Value & Range("Summary!C3").Value & ".xlsx"
Application.ScreenUpdating = False
 </code>[COLOR=#333333]End Sub[/COLOR][COLOR=#333333]
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
1. Fix your double quotes especially for worksheet names. Do find <code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;"> and replace <code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;"></code>with ".
</code>2. missing "s" for worksheets("sheetname")
 
Upvote 0
I see, didn't realize that is a thing or why it would be a thing, you can just delete this then, sorry.
 
Upvote 0
Actually im not sorry thats a ridiculous rule lol.. Just wants everyone to use his site only for maximum $
 
Upvote 0
Actually, its not a ridiculous rule. If read carefully, the rule isn't against cross-posting, the rule requires notice of the other posts.

Read this, it explain how many of the posters who answer question do so on many sites and don't want to duplicate their efforts.

https://www.excelguru.ca/content.php?184
 
Upvote 0
I just find it silly how im asking a question, and instead of someone helping me, they just post rules instead.
 
Upvote 0
I just find it silly how im asking a question, and instead of someone helping me, they just post rules instead.

Did you read the article at the link Mike posted in Message #7 yet? If not, please do so now... and pay particular attention to what is written under the heading "So What's the Big Deal?".
 
Upvote 0
To answer the VBA question, when specifying a sheet, one uses the Worksheets object not the Worksheet object.
Code:
Worksheet[U]s[/U](“Summary”).Unprotect "password"

' etc.
 
Last edited:
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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