VBA Loop to create Excel Sheet, save excel sheet to specific folder on computer and generate Outlook 365 Email with attached excel sheet.

dan24

New Member
Joined
Sep 12, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi All

I am hoping you can assist in how i would be able to writeup a VBA macro code that can resolve the below issue.

Summary: Looking to create a VBA macro that can check the vins in the attached sample excel sheet “MOND94 – BUGS CERT -Checklist” where it will identify each row through a VBA Loop to determine if I need to follow up load port and ask them using a customized message generated in Microsoft Outlook 365 to send certificates to me for that missing vin for that particular load port.

Each Vin in Column H would have an identifier next to it in Column I to determine if a certificate needs to be followed up as follows:

Y = Yes vin needs to be treated and no need to follow up certificate as you already have it on file.

N = Vin does not need to be treated as it is coming from a non risk country and no need to follow up certificate.

Blank = Vins need to be checked and certificate for treatment needs to be followed up.




Here are the below issues currently faced.

Issue 1: The VBA macro would need to start in sheet ‘Rpt_Discharge_Excel’ in Column H (VIN) row 1 and start searching from top to bottom for the Vin Numbers.

Next to Column H (VIN) is Column I (Bugs Treated) if cell is blank then I want the macro to generate a sheet for that load port in Column C pasting that entire row for that missing blank VIN in a sperate load port sheet.

Each load port would have an email address that I need to send to as found in the Load Port Sheet and also I need to save the load port sheet in a centralized folder in documents (It just needs to be in 1 folder) so that I can refer back to it if needed. Please note if I were to run the macro again I would like for the sheet when saved in a folder not to overwrite the current excel file but rather save the latest sheet based on date and time.


Issue 2: Would like to have an Outlook 365 Email generated with the attached excel Load Port sheet for those missing vins with customs message saying.
“Hi All
Please find attached excel sheet to send us certificates for the following vins”


Issue 3: The macro needs to know when the last row is so that it doesn’t keep looping infinitely and needs to stop at the last row in sheet ‘Rpt_Discharge_Excel’
Notes:

  • This macro would need to use some kind of do until loop or do loop, with if and else statements.
  • Vins can range from 17 digits to 4 digits.

MOND94 - BUGS CERT - Checklist.xlsm
ABCDEFGHIJKL
1VoyageDisch. PortLoad PortBook NoBL noCustomerBook Desc.VINBugs Treated?Reason for Non-TreatmentCheckerEmailed?
2MOND/94AUMELDEBRVAP002254FDEG5V94BRAD7014OPSKMOPSKM OCTAVIAUMBKU0NX7MY132456Y1
3MOND/94AUBNEDEBRVBP002244FDEG5V94BRAE7002OPAUNIOPAUNI Q3 - BBMXAUZZZF30M1117206Y1
4MOND/94AUBNEDEBRVBP002244FDEG5V94BRAE7002OPAUNIOPAUNI Q3 - BBMXAUZZZF31M11171031
5MOND/94AUBNEBEANRCE038629FDEG5V94ANAE0001BEFORMPUM 5 DOOR SUV HATCHXF02XXERK2MM09037Y1
6MOND/94AUBNEBEANRCE038629FDEG5V94ANAE0001BEFORMPUM 5 DOOR SUV HATCHXF02XXERK2MM895381
7MOND/94AUBNEBEANRCE038629FDEG5V94ANAE0001BEFORMPUM 5 DOOR SUV HATCHXF02XXERK2MP13458Y1
8MOND/94AUMELESSDRFS018073FDEG5V94SRAD0001ESDAMFuso Truck UYAFEB7UERDA101011
9MOND/94AUMELESSDRFS018073FDEG5V94SRAD0001ESDAMFuso Truck UYAFEB7UERDA101021
10MOND/94AUMELESSDRFS018073FDEG5V94SRAD0001ESDAMFuso Truck UYAFEB7UERDA10103Y1
11MOND/94AUBNEITLIVGS018234FDEG5V94LIAE0002ESITPROCube conveyor21CB021
12MOND/94AUBNEITLIVGS018234FDEG5V94LIAE0002ESITPROCube bifang21CS03Y1
13MOND/94AUBNEGBSOUKE038289FDEG5V94AMAE1000BEHYSCraneK117E01576VNNON-RISK ORIGIN0
14MOND/94AUBNEGBSOUKE038289FDEG5V94AMAE1000BEHYSForkliftK117E01576V-3NNON-RISK ORIGIN0
15MOND/94AUBNENLAMSZE038290FDEG5V94AMAE1001BEHYSMastK117E01577V-2Y1
16MOND/94AUBNENLAMSZE038290FDEG5V94AMAE1001BEHYSBoom fork liftK117E01577V-1Y1
17MOND/94AUBNENLAMSHE038294FDEG5V94AMAE1002BEHYSReachstakerK117E01580VY1
18MOND/94AUBNEGBNCLCE038504FDEG5V94NCAE1000BENCEUKNISSAN QASHQAISJNFBAJ11A2985897NNON-RISK ORIGIN0
19MOND/94AUBNEGBNCLCE038504FDEG5V94NCAE1000BENCEUKNISSAN QASHQAISJNFBAJ11A2990966NNON-RISK ORIGIN0
20MOND/94AUBNEGBNCLCE038504FDEG5V94NCAE1000BENCEUKNISSAN QASHQAISJNFBAJ11A2991067NNON-RISK ORIGIN0
Rpt_Discharge_Excel
Cell Formulas
RangeFormula
K2:K20K2=COUNTIF('Data Dump'!A:A,Rpt_Discharge_Excel!H2)


MOND94 - BUGS CERT - Checklist.xlsm
ABCD
1VINCheckerData Dump
2UMBKU0NX7MY1324561UMBKU0NX7MY132456
3XAUZZZF30M11172061XAUZZZF30M1117206
4XAUZZZF31M11171031XAUZZZF31M1117103
5XF02XXERK2MM090371XF02XXERK2MM09037
6XF02XXERK2MM895381XF02XXERK2MM89538
7XF02XXERK2MP134581XF02XXERK2MP13458
8UYAFEB7UERDA101011UYAFEB7UERDA10101
9UYAFEB7UERDA101021UYAFEB7UERDA10102
10UYAFEB7UERDA101031UYAFEB7UERDA10103
1121CB02121CB02
1221CS03121CS03
13K117E01577V-21K117E01577V-2
14K117E01577V-11K117E01577V-1
15K117E01580V1K117E01580V
Data Dump
Cell Formulas
RangeFormula
B2:B13B2=COUNTIF(Rpt_Discharge_Excel!H:H,'Data Dump'!A2)
A2:A15A2=LEFT(D2,17)


MOND94 - BUGS CERT - Checklist.xlsm
ABCDE
1Load PortCountriesLevel of RiskEmailSave Folder To
2DEBRVBremerhavenHigh Risk Countryjohnsmith@gmail.com;documents\bugs
3BEANRAntwerpHigh Risk Countryhelloworld@gmail.com; jaydensmith@outlook.com;documents\bugs
4ESSDRSantanderHigh Risk Countryjacksmith@hotmail.com;documents\bugs
5ITLIVLivornoHigh Risk Countryjamesmay@gmail.com; Jeremeyc.outlook.com; rh@gmail.com;documents\bugs
6NLAMSAmsterdamHigh Risk Countrydanjames@outlook.com;documents\bugs
7GBSOUSouthamptonNon Risk Countryryanmike@outlook.com;documents\bugs
8GBNCLNewcastle Non Risk Countrybobsmith@gmail.com;documents\bugs
Load Port


MOND94 - BUGS CERT - Checklist.xlsm
AB
1Disch. PortPort
2AUMELMelbourne
3AUPKLPort Kembla
4AUBNEBrisbane
Disch Port


Please advise if you can assist?

Best regards

Dan
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA Loop to create Excel Sheet, save excel sheet to specific folder on computer and generate Outlook 365 Email with attached excel sheet. - OzGrid Free Excel/VBA Help Forum
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top