danny147
Terugkerende gebruiker
- Lid geworden
- 29 apr 2007
- Berichten
- 4.744
Beste,
In de code die ik aangepast heb, krijg ik steeds een foutmelding --> zie rood gekleurd.
Kunnen jullie mij helpen waar het probleem zich schuilt ?
Groetjes Danny. :thumb:
In de code die ik aangepast heb, krijg ik steeds een foutmelding --> zie rood gekleurd.
Kunnen jullie mij helpen waar het probleem zich schuilt ?
Code:
Sub Uitvoeren_weekplanning()
Application.ScreenUpdating = False
Application.SheetsInNewWorkbook = 13
Workbooks.Add
ActiveWorkbook.SaveAs "D:\Weekplanning " & Format(Date, "d-mm-yyyy") & ".xlsx"
Dim bestandopen
bestandopen = Dir("D:\Danny\*")
Do Until bestandopen = ""
If bestandopen = "" Then Exit Do
Workbooks.Open "D:\Danny\" & bestandopen
With ActiveWorkbook.Sheets(1)
.Range("B1:k" & .Cells.SpecialCells(xlLastCell).Row).Copy _
Workbooks("Weekplanning " & Format(Date, "d-mm-yyyy") & ".xlsx").Sheets(1).Cells(Rows.Count, 2).End(xlUp).Offset(1)
End With
Application.DisplayAlerts = False
Workbooks(bestandopen).Close True
bestandopen = Dir
Loop
With Workbooks("Weekplanning " & Format(Date, "d-mm-yyyy") & ".xlsx")
With .Sheets(1)
On Error Resume Next
.Range("K2:K13000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
.Range("B3:K13000").Sort Key1:=Range("C2"), Order1:=xlAscending
Workbooks.Open "D:\Weekplanning.xlsx"
Workbooks("Weekplanning.xlsx").Sheets("Blad1").Range("A1").CurrentRegion.Copy .Range("AA1")
For i = 1 To .UsedRange.Rows.Count 'rijen
For j = 1 To 11 'kolommen
.Cells(i, j) = RTrim(.Cells(i, j))
.Cells(i, 9) = Split(.Cells(i, 9))
.Cells(i, 8) = Split(.Cells(i, 8))
Next j
Next i
For Each cdt In .Columns(9).SpecialCells(2)
cdt.Value = Split(cdt.Value)
If cdt Like "##-##-####" Or cdt Like "##-#-####" Or cdt Like "#-#-####" Or cdt Like "#-##-####" Then
cdt.Value = DateValue(cdt)
cdt.NumberFormat = "dd-mm-yyyy"
End If
Next cdt
.Range("B2:K" & .Cells.SpecialCells(11).Row).AutoFormat Format:=xlRangeAutoFormatClassic1
.Cells.Borders(xlInsideHorizontal).LineStyle = xlNone
.Columns.AutoFit
End With
Workbooks("Weekplanning.xlsx").Close True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Dim cl As Range
Dim C As Variant
Dim Rij As Long
Application.ScreenUpdating = False
sq = "Roepnaam" & "|" & "Machine" & "|" & "Omschrijving" & "|" & "Werkorder" & "|" & "Status" & "|" & "OnderhoudsType" & "|" _
& "BeginTijdstipGepland" & "|" & "EindTijdstipGepland" & "|" & "CapacitaitsgroepID" & "|" & "Werkvoorbereider" & "|"
[COLOR="#FF0000"][B]For Each cl In .Range("C2:C" & .Cells(Rows.Count, 3).End(xlUp).Row)[/B] [/COLOR]
If cl > 0 Then
Set C = .Range("A2:L15").Find(cl, , xlValues, xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
kolom = Mid(C.Address, 3, 1)
Select Case kolom
Case "A"
With Sheets("Blad2").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad2")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad2").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "B"
With Sheets("Blad3").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad3")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad3").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "C"
With Sheets("Blad4").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad4")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad4").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "D"
With Sheets("Blad5").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad5")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad5").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "E"
With Sheets("Blad6").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad6")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad6").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "F"
With Sheets("Blad7").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad7")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad7").Columns("E:K").HorizontalAlignment = xlCenter
Sheets("Blad1").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "G"
With Sheets("Blad8").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad8")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad8").Columns("E:K").HorizontalAlignment = xlCenter
Sheets("Blad1").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "H"
With Sheets("Blad9").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad9")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad9").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "I"
With Sheets("Blad10").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad10")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad10").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "J"
With Sheets("Blad11").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad11")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad11").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "K"
With Sheets("Blad12").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad12")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad12").Columns("E:K").HorizontalAlignment = xlCenter
End With
Case "L"
With Sheets("Blad13").Cells(Rows.Count, 3).End(xlUp)
If cl <> naam Then
Rij = .Offset(1).Row
.Offset(1, -2).Resize(, 11).Interior.ColorIndex = 37
.Offset(1, -2) = cl
.Offset(1, -1).Resize(, 10) = Split(sq, "|")
End If
End With
With Sheets("Blad13")
.Cells(Rows.Count, 3).End(xlUp).Offset(1, -1).Resize(, 11) = cl.Offset(, -1).Resize(, 11).Value
.Range(.Cells(Rij, 1), .Cells(.Cells(Rows.Count, 3).End(xlUp).Row, 11)).Sort .Cells(Rij - 1, 10), , , , , , , xlYes
Sheets("Blad13").Columns("E:K").HorizontalAlignment = xlCenter
End With
End Select
Set C = .Range("A2:L15").FindNext(C)
Loop While Not C Is Nothing And C.Address <> firstAddress
End If
End If
If Not cl Is Nothing Then
naam = cl
End If
Next cl
For i = .Range("C2:C" & .Cells(Rows.Count, 3).End(xlUp).Row).Rows.Count To 2 Step -1
If .Cells(i, 3) > 0 Then
Set C = .Range("A2:L15").Find(.Cells(i, 3), , xlValues, xlWhole)
If Not C Is Nothing Then
.Cells(i, 3).Offset(, -2).Resize(, 11).Delete shift:=xlUp
End If
End If
Next i
For i = .Range("I2:I" & .Cells(Rows.Count, 10).End(xlUp).Row).Rows.Count To 2 Step -1
If .Cells(i, 10) = "726.EW" Then .Cells(i, 1).Resize(, 11).Delete shift:=xlUp
Next i
End With
Dim wrksht As Worksheet
For Each wrksht In Worksheets
wrksht.Columns.AutoFit
Next wrksht
For i = 1 To 14
Sheets("Blad" & i).Name = Choose(i, "Maandag Controle", "Maandag Onderhoud", "Dinsdag Controle", "Dinsdag Onderhoud", "Woensdag Controle", "Woensdag Onderhoud", "Donderdag Controle", "Donderdag Onderhoud", "Vrijdag Controle", "vrijdag Onderhoud", "Zaterdag Controle", "zaterdag Onderhoud")
Next
For x = 1 To 14
Sheets(Choose(x, "Maandag Controle", "Maandag Onderhoud", "Dinsdag Controle", "Dinsdag Onderhoud", "Woensdag Controle", "Woensdag Onderhoud", "Donderdag Controle", "Donderdag Onderhoud", "Vrijdag Controle", "vrijdag Onderhoud", "Zaterdag Controle", "zaterdag Onderhoud")).Range("A2").AutoFilter
Next
Windows("Weekplanning " & Format(Date, "d-mm-yyyy") & ".xlsx").Activate
With Application
.ScreenUpdating = True
.SheetsInNewWorkbook = 3
.Save
.Close True
End With
End Sub
Groetjes Danny. :thumb: