Romano_odK
Active Member
- Joined
- Jun 4, 2020
- Messages
- 380
- Office Version
- 365
- Platform
- Windows
Good afternoon,
Got a macro and in the macro I would like to stop it running if there is an error in the IF statements below. Is that possible?
Thank you for your help.
Got a macro and in the macro I would like to stop it running if there is an error in the IF statements below. Is that possible?
Thank you for your help.
VBA Code:
Action = True
If Worksheets("Boekingen").Cells(2, 2) = Empty Then
MsgBox ("Export folder niet gevuld")
Action = False
End If
Action = True
If Worksheets("Boekingen").Cells(6, 11) = Empty Then
MsgBox ("'Van locatie' niet gevuld")
Action = False
End If
Action = True
If Worksheets("Boekingen").Cells(6, 12) = Empty Then
MsgBox ("'Aantal' niet gevuld")
Action = False
End If
Action = True
If Worksheets("Boekingen").Cells(6, 13) = Empty Then
MsgBox ("Verplaats' niet gevuld")
Action = False
End If
Action = True
If Worksheets("Boekingen").Cells(1, 2) = Empty Then
MsgBox ("Datum niet gevuld")
Action = False
End If
' Medewerker = Worksheets("Boekingen").Cells(4, 2)
' ----------------------------------------------------------------------------------------
' Step 2: Write records for Boekingen
' ----------------------------------------------------------------------------------------
Itemrow = 6
While Worksheets("Boekingen").Cells(Itemrow, 1) <> Empty And Action
Datum = Worksheets("Boekingen").Cells(1, 2)
Artikelcode = Worksheets("Boekingen").Cells(Itemrow, 1)
Bedrag = Worksheets("Boekingen").Cells(Itemrow, 3)
Vrrdrek = Worksheets("Boekingen").Cells(Itemrow, 6)
Magazijn = Worksheets("Boekingen").Cells(Itemrow, 7)
LocatieVan = Worksheets("Boekingen").Cells(Itemrow, 11)
LocatieNaar = Worksheets("Boekingen").Cells(Itemrow, 12)
Aantal = Worksheets("Boekingen").Cells(Itemrow, 13)
'
Call WriteRecord(a)
Itemrow = Itemrow + 1
Wend
' ----------------------------------------------------------------------------------------
' Step 3: End file
' ----------------------------------------------------------------------------------------
If Action = True Then
a.WriteLine ("</GLEntries>")
End If
a.WriteLine ("</eExact>")
a.Close
End Sub
Private Sub WriteRecord(ByVal a As Object)
a.WriteLine ("<GLEntry entry=""""" & " status=""E"">")
a.WriteLine ("<Description>" & Omschrijving & "</Description>")
a.WriteLine ("<Date>" & Datum & "</Date>")
a.WriteLine ("<Journal code=""" & Dagboek & """ type=""M""/>")
a.WriteLine ("<FinEntryLine number=""" & Itemrow - 11 & """ type= ""N"" subtype=""G"">")
a.WriteLine ("<Date>" & Datum & "</Date>")
a.WriteLine ("<GLAccount code=""" & Vrrdrek & """/>")
a.WriteLine ("<Costcenter code=""" & KPL & """/>")
a.WriteLine ("<Description>" & Omschrijving & "</Description>")
a.WriteLine ("<Item code=""" & Artikelcode & """/>")
a.WriteLine ("<Warehouse code=""" & Magazijn & """/>")
a.WriteLine ("<WarehouseLocation code=""" & LocatieNaar & """/>")
a.WriteLine ("<Quantity>" & Replace(Aantal, ",", ".") & "</Quantity>")
a.WriteLine ("<Amount><Currency code=""EUR""/><Debit>" & Replace(Bedrag * Aantal, ",", ".") & "</Debit></Amount>")
a.WriteLine ("</FinEntryLine>")
a.WriteLine ("<FinEntryLine number=""" & Itemrow - 11 & """ type= ""N"" subtype=""G"">")
a.WriteLine ("<Date>" & Datum & "</Date>")
a.WriteLine ("<GLAccount code=""" & Vrrdrek & """/>")
a.WriteLine ("<Costcenter code=""" & KPL & """/>")
a.WriteLine ("<Description>" & Omschrijving & "</Description>")
a.WriteLine ("<Item code=""" & Artikelcode & """/>")
a.WriteLine ("<Warehouse code=""" & Magazijn & """/>")
a.WriteLine ("<WarehouseLocation code=""" & LocatieVan & """/>")
a.WriteLine ("<Quantity>" & Replace(Aantal * -1, ",", ".") & "</Quantity>")
a.WriteLine ("<Amount><Currency code=""EUR""/><Debit>" & Replace(Bedrag * Aantal * -1, ",", ".") & "</Debit></Amount>")
a.WriteLine ("</FinEntryLine>")
a.WriteLine ("</GLEntry>")