Private Sub Commandbutton1_click Syntax Error
Contents |
team • Delete all
Compile Error Expected Expression
board cookies • All times are UTC - 5 hours Terms of use | Privacy policy Powered by phpBB Forum Software © phpBB Group We retain the rights to all posts and threads. We are not affiliated with Microsoft.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Syntax Error in Excel http://www.excelkey.com/forum/viewtopic.php?f=3&t=3204 2013 Macro [duplicate] up vote 0 down vote favorite This question already has an answer here: VBA multi-parameter function call Syntax Error 2 answers Calling a Sub in VBA 1 answer My son is helping me between classes and asked me to post this bit of code that is coming back with a syntax error. He is trying to code an Excel 2013 Macro for me http://stackoverflow.com/questions/26812058/syntax-error-in-excel-2013-macro to do volunteer assignments for multiple jobs over a three month time period with repeats allowed only every 4 weeks. He is knowledgeable in C++ but has not done this with Excel before. This is the piece that is coming back highlighted: Private Sub CommandButton1_Click() findname(Range("C2", "C11"), Range("B2", "B11"), 10, 1, Range("G2", "G2")) End Sub This is the other piece he has written which he says should work fine once the syntax error is fixed: Public Sub findname(ByRef name As Range, ByRef cv As Range, _ length As Integer, weekno As Integer, ByRef voluntold As Range) newVal = -1 Do newVal = WorksheetFunction.RandBetween(1, length) If (WorksheetFunction.Index(cv, newVal).Value / weekno >= 1) Then newVal = -1 Else WorksheetFunction.Index(cv, newVal).Value = _ WorksheetFunction.Index(cv, newVal).Value + 4 End If Loop While newVal = -1 WorksheetFunction.Index(voluntold, 1).Value = WorksheetFunction.Index(name, newVal) End Sub excel excel-vba share|improve this question edited Feb 9 '15 at 22:08 pnuts 33.9k63870 asked Nov 7 '14 at 23:58 Christ Lutheran Church Fairban 1 marked as duplicate by chris neilsen, Ken White, xmojmr, Siddharth Routexcel-vba Users with the excel-vba badge can single-handedly close excel-vba questions as duplicates and reopen them as needed. Nov 8 '14 at
Introducing Worksheets Start Microsoft Excel or a new document To save the document, press Ctrl + S Save it as ROSH1 On the Ribbon, click Developer In the Code section, click http://www.functionx.com/vbaexcel/Lesson14.htm the Visual Basic button To create a form, on the main menu of Microsoft http://www.excelforum.com/showthread.php?t=549169 Visual Basic, click Insert -> UserForm Right-click the form and click Properties Change its Caption to Red Oak High School - Management Identifying a Worksheet A worksheet is an object of type Worksheet. The various worksheets you will use are stored in a collection called Worksheets. Another name for the collection that contains the worksheets is compile error called Sheets. In most cases, you can use either of these two collections. Each worksheet is an object of type Worksheet. Referring to a Worksheet In the previous lesson, we saw that, if you have only one workbook opened, to refer to it, you can pass an index of 1 to the Item property of the Workbooks collection to access its Workbook object. Here is an example: Sub Exercise() Workbooks.Item(1) End compile error syntax Sub You can omit the Item name if you want and you would get the same result: Sub Exercise() Workbooks(1) End Sub Because the worksheets of a document are part of the workbook that is opened, to support them, the Workbook class is equipped with a property named Worksheets or Sheets. Therefore, after identifying the workbook, use the period operator to access the Worksheets or the Sheets property. Here is an example: Sub Exercise() Workbooks.Item(1).Sheets End Sub As mentioned already, the worksheets are stored in the Worksheets collection, which is actually a class. Each worksheet can be located based on an indexed property named Item. The Item property is a natural number that starts at 1. The most left worksheet has an index of 1. The second worksheet from left has an index of 2, and so on. To access a worksheet, type one of the Worksheets or Sheets collections, followed by the period operator, followed by Item() and, between the parentheses, type the index of the worksheet you want. For example, the following code will access the second worksheet from left: Private Sub Exercise() Workbooks.Item(1).Sheets.Item(2) End Sub Just as we saw that you can omit the Item word on the Workbooks object, you can also omit it on the Wor
Forum Microsoft Office Application Help - Excel Help forum Excel General Excel - New Users/Basics how do i make a commandbutton run a macro?? To get replies by our experts at nominal charges, follow this link to buy points and post your thread in our Commercial Services forum! Here is the FAQ for this forum. + Reply to Thread Results 1 to 8 of 8 how do i make a commandbutton run a macro?? Thread Tools Show Printable Version Subscribe to this Thread… Mark this thread as solved… Rate This Thread Current Rating Excellent Good Average Bad Terrible Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 06-06-2006,04:25 PM #1 Shax Guest how do i make a commandbutton run a macro?? I have this project i have to do for work and i want the commandbuttons to open seperate sheets within the workbook - but i dont understand all this visual basic language stuff so can someone please translate it into a dummy version for me - i can run a macro by recording it but how do i make the macro perform within the button??? i remember doing it in college but can not rem think it was an older version - all help is appreciated. thank you for ur time and many regards Register To Reply 06-06-2006,04:35 PM #2 RJ Guest RE: how do i make a commandbutton run a macro?? There are a couple easy ways to do this. I guess the easiest would be to right click on the command button and go to view code and insert the following code. Private Sub CommandButton1_Click() Application.Run "YourWorkbookName!YourMacroName" End Sub Where YourWorkbookName will be the name of the workbook you are workign in and the YourMacroName will be the name of the Macro you want the commandbutton to open. "Shax" wrote: > I have this project i have to do for work and i want the commandbuttons to > open seperate sheets within the workbook - but i dont understand all this > visual basic language stuff so can someone please translate it into a dummy > version for me - i can run a macro by recording it but how do i make the > macro perform within the button??? i remember doing it in college but can not > rem think it was an older version - all help is appreciated. > > thank you for ur time and many regards > > > Register To Reply 06-0