VBA Error: “Compile error: Expected End Sub”
You can’t nest a function inside a procedure. You need to move it above:
You can’t nest a function inside a procedure. You need to move it above:
Use the below function (changing [E:E] to the appropriate range for your needs) to circumvent this issue (or change to any other format such as “mm/dd/yyyy”): P.S. In my experience, this VBA solution works SIGNIFICANTLY faster on large data sets and is less likely to crash Excel than using the ‘warning box’ method.
“Run-time error ‘3061’. Too few parameters. Expected 1.” I believe this happens when the field name(s) in your sql query do not match the table field name(s), i.e. a field name in the query is wrong or perhaps the table is missing the field altogether.
In the VBA editor, go to View, Toolbars, Customise… or right click on the tool bar and select Customise… Under the Commands tab, select the Edit menu on the left. Then approximately two thirds of the way down there’s two icons, Comment Block and Uncomment Block. Drag and drop these onto your toolbar and then you have easy access to highlight a block of code, and comment … Read more
I suspect you haven’t set up last_name properly in the caller. With the statement Worksheets(data_sheet).Range(“C2”).Value = ProcessString(last_name) this will only work if last_name is a string, i.e. appears in the caller somewhere. The reason for this is that VBA passes in variables by reference by default which means that the data types have to match exactly between caller and callee. Two fixes: … Read more
I use and recommend Rubberduck. Description from the website: Rubberduck is a very active open-source COM add-in project that integrates with the Visual Basic Editor to enable the features every programmer wants to have in their IDE. From unit testing to source control, from code inspections to refactorings, programming in VBA will never be the same.
On the line with the first If, you must go to a new line after Then, otherwise your If will be implicitely closed.
Use the Application.Match function which allows for better ability to trap errors. When using the WorksheetFunction.Match, when a match is not found, it returns an error, which is what you’re experiencing. You could also potentially use the CountIf function: Neither of these approaches requires you to use the m1 variable, you can assign this variable within the True part of the If/Then statement, if you need … Read more
Below is a solution from here
I’ve found a workaround. At first it seemed it would take up more time, but it actually makes everything work smoother and faster due to less swapping and more memory available. This is not a scientific approach and it needs some testing before it works. In the code, make Excel save the workbook every now … Read more