1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Sub EnvoiMailRappel()
'Declare Variables
Dim TsrFichOri As String, TsrTabEnvoiManuel As String, RefClient As String
Dim strInputBox As String
Dim wb As Workbook, ws As Worksheet
Dim rowNumber As Long, myDate As Date
Dim EmailClient As String, NomClient As String, ComStru As String
Dim Montant As String, FirstDate As Date
'Initialize Variables
Range("A1").Activate
TsrFichOri = ActiveWorkbook.Name
TsrTabEnvoiManuel = "Envoi manuel"
Windows(TsrFichOri).Activate
Worksheets(TsrTabEnvoiManuel).Activate
'Prompt User for Client Reference
RefClient = InputBox("Veuillez entrer la référence du client", "Input required")
'Exit Macro if User Presses Cancel
If RefClient = "" Then Exit Sub
' Copy relevant rows from old workbook and create a new workbook with that data
Rows(1).Copy
Workbooks.Add
ActiveSheet.Paste
'Find first row with reference
rowNumber = Columns(1).Find(What:=RefClient, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Row
FirstDate = Cells(rowNumber, 6).Value
'Find row with "Total " & RefClient
rowNumber = Columns(1).Find(What:="Total " & RefClient, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Row
'Extract necessary values
EmailClient = Cells(rowNumber, 3).Value
NomClient = Cells(rowNumber, 4).Value
Montant = Cells(rowNumber, 11).Value
ComStru = Cells(rowNumber - 1, 12).Value
End Sub |
Partager