You could use the following - if Value in Worksheet Boleto I5 not in Worksheet Fin Column A then save workbook
Sub Botão6_Clique()
Dim rCell As Range, iRow As Long, fnRng As Range
Dim wsBoleto As Worksheet, wsFIN As Worksheet
Set wsBoleto = Worksheets("Boleto")
Set wsFIN = Worksheets("FIN")
With wsFIN
iRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
End With
With wsBoleto
For Each rCell In .Range("E16,I7,G9,G13,E19,G19")
If IsEmpty(rCell) Then
MsgBox "Uma ou mais campos estão vazios, favor preencher todos os campos ...", _
vbInformation, "Preenchimento Obrigatório"
Exit Sub
End If
Next rCell
.Range("L7").Value = wsFIN.Cells(iRow, 1).Offset(-1, 0).Value + 1
End With
With wsFIN
.Cells(iRow, 1).Value = wsBoleto.Range("L7").Value
.Cells(iRow, 2).Value = wsBoleto.Range("E16").Value
.Cells(iRow, 3).Value = wsBoleto.Range("I7").Value
.Cells(iRow, 4).Value = wsBoleto.Range("G11").Value
.Cells(iRow, 5).Value = wsBoleto.Range("G9").Value
.Cells(iRow, 6).Value = wsBoleto.Range("G13").Value
.Cells(iRow, 7).Value = wsBoleto.Range("E19").Value
.Cells(iRow, 8).Value = wsBoleto.Range("G19").Value
MsgBox "Os dados foram salvos!!" & vbNewLine & _
"Registro número: " & .Cells(iRow, 1).Value
End With
With wsBoleto
.Range("E16,I7,G9,G13,E19,G19").ClearContents
End With
'Additional code to check condition to save
Set fnRng = wsFIN.Columns(1).Find(wsBoleto.Range("I5"), wsFIN.Cells(1, 1), xlValues, xlWhole)
If Not fnRng Is Nothing Then
'value is present
'you could exit sub
Exit Sub
Else
'Value not present
ActiveWorkbook.Save
End If
End Sub
Bookmarks