Apr 23 2021 11:58 AM
Apr 23 2021 11:58 AM
I have an excel sheet (attached)that generates delivery reports based on the Delivery nr. entered. The information on the delivery note is pulled from a source table that has all the data. After entering a delivery note nr. in cell E7, I have to "Select All" in the description column then deselect the hyphen so as to have a neat report without the blank rows.
I would like to be assisted with;
1. a code that will do above in one click. If possible, after "selecting all and deselecting the hyphen, the code to print preview.
2. Is there a possibility of generating multiple delivery reports from an excel table with data.At the moment, I can only enter one delivery note number at time.
Apr 23 2021 07:34 PMSolution
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.
Apr 24 2021 12:30 PM
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.
Apr 24 2021 12:49 PM - edited Apr 24 2021 12:50 PM
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).