XL 2013 modif code vba

titooooo

XLDnaute Occasionnel
Bonjour

ci dessous un code qui propose d'ouvrir un autre classeur excel mais je veut que ca sera du même classeur

j'ai besoin de modifier le code vba suivant
afin qu'il récupère les info de ce meme classeur de la feuille horaire du format suivant
journée ( type lun , mar ,,,,,) : heure d'arrivé H ; heure de départ


Sub sms()
Dim tabhor()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "sélectionnez le fichier planning de la semaine"
.Filters.Clear
.Filters.Add "Excel files", "*.XLS*"
If .Show = True Then
fname = .SelectedItems(1)
Else
MsgBox "no files selected"
Exit Sub
End If
End With
Set wss = ThisWorkbook.Sheets("Feuil1")
Set wsst = ThisWorkbook.Sheets("Feuil2")
wsst.Cells.Clear
dlst = 1
wsst.Cells(1, 1) = "sans N° de téléphone"
wss.Cells(2, 1).Resize(3000, 5).Clear
dls = 1
Set wb = Workbooks.Open(fname)
Set wsp = wb.Sheets("horaire")
Set wst = wb.Sheets("Tel")
dlt = wst.Cells(Rows.Count, 1).End(xlUp).Row
Set plgtel = wst.Cells(2, 1).Resize(dlt - 1, 1)
dlp = wsp.Cells(Rows.Count, 2).End(xlUp).Row
For i = 7 To dlp
ecart = Val(wsp.Cells(i, "U"))
regime = Val(wsp.Cells(i, "S"))
comm = wsp.Cells(i, "V")
'If regime + ecart = 0 And comm <> "CP" Then
' 'exclure
'Else
msg = ""
sep = ""
For j = 23 To 228 Step 34 'col W a col HT
jour = Format(wsp.Cells(4, j), "ddd") & "."
msg = msg & sep & jour & " "
horaire = ""
ReDim tabhor(5, 2)
th = 0
For j1 = 0 To 5 Step 2
If wsp.Cells(i, j + j1) = "" Then Exit For
If wsp.Cells(i, j + j1 + 1) = "" Then horaire = wsp.Cells(i, j + j1): Exit For
th = th + 1
tabhor(th, 1) = wsp.Cells(i, j + j1)
tabhor(th, 2) = wsp.Cells(i, j + j1 + 1)
Next j1
For j1 = 14 To 17 Step 2
If wsp.Cells(i, j + j1) = "" Then Exit For
If wsp.Cells(i, j + j1 + 1) = "" Then MsgBox " horaire de formation invalide en ligne " & i: Exit Sub
th = th + 1
tabhor(th, 1) = wsp.Cells(i, j + j1)
tabhor(th, 2) = wsp.Cells(i, j + j1 + 1)
Next j1
If th > 0 Then
arrangetable tabhor, th
For j1 = 1 To th
horaire = horaire & Format(tabhor(j1, 1), "hh:mm") & "-" & Format(tabhor(j1, 2), "hh:mm") & " "
Next j1
End If
If horaire = "" Then horaire = "OFF"
msg = msg & horaire
sep = vbCrLf
Next j
abcd = wsp.Cells(i, 2)
msg = Replace(msg, ":", "h")
msg = Replace(msg, "h00", "h")
Set re = plgtel.Find(abcd, lookat:=xlWhole, LookIn:=xlValues)
If re Is Nothing Then
f = False
ElseIf re.Offset(, 2) = 0 Then
f = False
Else
f = True
End If
If f = False Then
dlst = dlst + 1
wsst.Cells(dlst, 1) = abcd
wsst.Cells(dlst, 2) = wsp.Cells(i, "I")
wsst.Cells(dlst, 3) = msg
Else
dls = dls + 1
wss.Cells(dls, 1) = re.Offset(, 2)
wss.Cells(dls, 2) = re.Offset(, 1)
wss.Cells(dls, 3) = msg
End If
'End If
Next i
wb.Close False
End Sub

Sub arrangetable(ByRef tabhor, th)
For i = 1 To th - 1
For j = i + 1 To th
If tabhor(i, 1) > tabhor(j, 1) Then
For k = 1 To 2
a = tabhor(i, k)
tabhor(i, k) = tabhor(j, k)
tabhor(j, k) = a
Next k
End If
Next j
Next i
For i = th To 2 Step -1
If tabhor(i, 2) < tabhor(i - 1, 2) Then
If tabhor(i, 1) < tabhor(i - 1, 1) Then
tabhor(i - 1, 1) = tabhor(i, 1)
th = th - 1
Else
th = th - 1
End If
ElseIf tabhor(i, 1) = tabhor(i - 1, 2) Then
tabhor(i - 1, 2) = tabhor(i, 2)
th = th - 1
End If
Next i
End Sub
 

Pièces jointes

  • Macro (1).xls
    64 KB · Affichages: 15

Discussions similaires

Réponses
11
Affichages
280
Réponses
2
Affichages
76

Statistiques des forums

Discussions
312 069
Messages
2 085 040
Membres
102 763
dernier inscrit
NICO26