An Excel Office Script that automates the process of comparing shipment data between two worksheets, identifies missing shipments, and creates organized customer-specific reports.
This system helps logistics teams quickly identify which shipments from their main document are missing from their control tracking sheet. It automatically generates individual worksheets for each customer containing their missing shipment details, formatted for easy review and action.
- Compares Two Data Sources: Matches shipment IDs between your main shipment document and a control tracking sheet
- Identifies Missing Shipments: Finds which shipments exist in your main document but are missing from the control sheet
- Creates Customer-Specific Reports: Generates separate worksheets for each customer containing only their missing shipments
- Provides Summary Information: Shows you exactly which shipments were found and which were not found
- Cleans and prepares your origin document by removing unnecessary columns
- Extracts all unique shipment IDs from both worksheets
- Performs the comparison to identify matches and mismatches
- Creates a summary section showing the results
- Generates individual customer worksheets with missing shipment details
- Applies formatting and formulas for better readability
Your workbook must contain these two worksheets:
- "Origin Document" Worksheet This contains your main shipment data with these expected columns:
- Shipment ID (required - used for comparison)
- Vessel Name
- Voyage No
- Est Depart Date
- Discharge Location
- Arrival Location
- PO No
- Master BL No
- Container No
- Freight Type
- Date Range
Note: Depending on your business requirements, the script can automatically remove columns like "Ship Mode", "Seal No", "Cartons". To understand how the script works, if you don't know the data, just put a placeholder value.
- "kontrol" Worksheet
This contains your reference shipment IDs for comparison. The script will:
- Process all cells in this worksheet
- Extract unique shipment IDs
- Use these as the reference list for comparison
Excel with Office Scripts enabled (Excel for web, Excel for Windows with Microsoft 365) Your data organized in the two required worksheets
- Prepare Your Data
- Ensure your main shipment data is in a worksheet named "Origin Document"
- Ensure your control/reference data is in a worksheet named "kontrol"
- Make sure shipment IDs are in the first column of your origin document
- Run the Script
- Open the Office Scripts panel in Excel
- Paste the script code into a new script
- Click "Run" to execute
- Review the Results
- Check the summary section added to your "Origin Document" worksheet
- Review the individual customer worksheets created for missing shipments
- Data Cleaning: The header rows and the columns you specify are removed from your origin document
- Comparison Process: All shipment IDs are extracted and compared against the shipment IDs in the kontrol sheet.
- Summary Creation: A table is added to your origin document showing:
- "ShipKeys Found" column: Shipments that exist in both documents
- "ShipKeys NOT Found" column: Shipments missing from the control sheet
- Customer Worksheets: Individual sheets are created for each customer with missing shipments
Located at the bottom of your "Origin Document" worksheet:
- Shipment IDs found in the kontrol sheet,
- Shipment IDs not found in the kontrol sheet.
- Formatted with color-coded headers and proper date formatting
- Green columns: Primary shipment information (Shipment ID, Vessel Name, etc.)
- Red columns: Secondary reference information (Booking ID, Shipper, etc.)
- Contains only that customer's missing shipment data
- Includes a formula combining Shipment ID and Booking ID
The script assumes that the first 3 characters of each shipment ID represent the customer code. For example:
- Shipment ID "ABC123456" → Customer "ABC"
- Shipment ID "XYZ789012" → Customer "XYZ"
If your shipment IDs use a different customer identification pattern, you'll need to modify the getNotFoundCustomers()
function.
In the cleanSheet()
function, you can adjust the columnDeletes array to change which columns are removed:
const columnDeletes = [
"Ship Mode",
"Destination Service Type",
"Est Discharge Date",
// Add or remove column names as needed
];
Modify this line in getNotFoundCustomers()
to change how customer codes are extracted:
// Current: uses first 3 characters
notFoundCustomersArr.push(shipKey.slice(0, 3));
// Example: use characters 4-6 instead
notFoundCustomersArr.push(shipKey.slice(3, 6));
In createNotFoundCustomerSheets()
, you can modify:
- greenBackgoundHeaders: Columns with green background (primary data)
- redBackgroundHeaders: Columns with red background (secondary data)
- tableHeaders: All available column headers
Ensure your main data worksheet is named exactly "Origin Document" Check for extra spaces or different capitalization
Ensure your control worksheet is named exactly "kontrol" (lowercase)
Verify that some shipments are actually missing from the control sheet Check that shipment IDs follow the expected format (customer code in first 3 characters)
Ensure your origin document has data starting from the expected row/column positions Check that shipment IDs are in the first column
- Large datasets (10,000+ rows) may take several minutes to process
- The script logs progress information to the console for monitoring
- Consider running during off-peak hours for very large datasets
- Excel Office Scripts environment
- No external libraries required
- Works in Excel for web (all modern browsers)
- Compatible with Excel for Windows with Microsoft 365 subscription
- Maximum worksheet size limits apply (Excel's standard limits)
- Script memory limitations may affect very large datasets
When contributing to this script:
- Maintain Verbose Comments: All functions should have detailed explanations
- Use Explicit Variable Names: Prefer shipmentKeyArray over arr
- Add Debug Logging: Include console.log statements for troubleshooting
- Test with Sample Data: Verify changes work with realistic datasets
This project is GPL v2.0 open source. Please include attribution when redistributing or modifying.
For issues or questions:
- Check the troubleshooting section above
- Review the detailed code comments for specific function behavior
- Test with a small sample dataset first
- Ensure your data format matches the expected structure
Last Updated: May 2025 Compatible With: Excel Office Scripts, Microsoft 365