Forum Discussion
VBA code
- Apr 24, 2021
I attached an example that may give you some ideas. I added a worksheet with a structured table to list the delivery numbers to include in a "batch processing" function. The filter and print preview is triggered by the worksheet change event handler. Then, there is a button that triggers the batch processing, which will get the delivery numbers from the table on Sheet2, then pass them to the Delivery Note worksheet, which will change the value in the delivery number cell and trigger the change event handler.
So, you should be able to input a delivery number yourself, or run a batch.
I attached an example that may give you some ideas. I added a worksheet with a structured table to list the delivery numbers to include in a "batch processing" function. The filter and print preview is triggered by the worksheet change event handler. Then, there is a button that triggers the batch processing, which will get the delivery numbers from the table on Sheet2, then pass them to the Delivery Note worksheet, which will change the value in the delivery number cell and trigger the change event handler.
So, you should be able to input a delivery number yourself, or run a batch.
- A_SIRATApr 24, 2021Iron Contributor
Hi JMB17,
I modified the excel file to reflect what I really want in your original file and it worked perfectly. However, after coping the code to my other workbook, I got below error. I am not good with VBA but I think the sheet names could be bringing the error. Please assist.
- JMB17Apr 24, 2021Bronze Contributor
Yes, the sheet name will need to be changed. My code is using the worksheet code name, which may or may not be the same as the worksheet tab name.
If you open the vba project explorer (view/project explorer) and expand the "Microsoft Excel Objects" under your workbook, you will see your worksheets listed. Each worksheet has two names - the first name is the "code name" and the second is the worksheet tab name (the one in parentheses).
You will need to replace Sheet1 with the code name that actually contains your list of delivery numbers and the "GetDeliveryNumbers" function. Alternatively, you could reference the worksheet using the tab name with Worksheets("TabNameHere").GetDeliveryNumbers (but then it would fail if the tab name is ever changed - using the worksheet code name is generally more reliable).