Sub RIVIERENLAND_ZGV_KPL_OPZOEKEN_NIEUW_TEST()
'
' RIVIERENLAND_ZGV_KPL_OPZOEKEN_NIEUW Macro
'
Sheets("Samenvatting").Select
Columns("A:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("L:L").Select
Selection.Cut
Columns("A:A").Select
ActiveSheet.Paste
Columns("J:J").Select
Selection.Cut
Columns("B:B").Select
ActiveSheet.Paste
Columns("M:M").Select
Selection.Cut
Columns("C:C").Select
ActiveSheet.Paste
Columns("O:O").Select
Selection.Cut
Columns("D:D").Select
ActiveSheet.Paste
Columns("P:P").Select
Selection.Cut
Columns("E:E").Select
ActiveSheet.Paste
Columns("U:U").Select
Selection.Cut
Columns("F:F").Select
ActiveSheet.Paste
Columns("I:I").Select
Selection.Cut
Columns("G:G").Select
ActiveSheet.Paste
Columns("H:Z").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.LargeScroll ToRight:=-1
Range("A1").Select
ActiveCell.FormulaR1C1 = "GEBOORTEDATUM"
Range("B1").Select
ActiveCell.FormulaR1C1 = "KOSTENPLAATS"
Range("C1").Select
ActiveCell.FormulaR1C1 = "NAAM"
Range("D1").Select
ActiveCell.FormulaR1C1 = "CODE PRESTATIE"
Range("E1").Select
ActiveCell.FormulaR1C1 = "DATUM PRESTATIE"
Range("F1").Select
ActiveCell.FormulaR1C1 = "KOSTEN"
Range("G1").Select
ActiveCell.FormulaR1C1 = "BSN"
Columns("A:G").Select
Columns("A:G").EntireColumn.AutoFit
Dim sn, c As Range, dGeboorte As Date, dBegin As Date, sNaam As String, l As Long, WB As Workbook, splits, bOpen As Boolean
splits = Split("H:\ziekenhuis facturen\rapportage labnotas\rapportage_nieuw.xlsx ", "\")
On Error Resume Next
Set WB = Workbooks(splits(UBound(splits)))
bOpen = Not (WB Is Nothing)
If Not bOpen Then
Set WB = Workbooks.Open(Join(splits, "\"))
If WB Is Nothing Then
MsgBox "kan die file niet openen", vbCritical: Exit Sub
End If
End If
On Error GoTo 0
sn = WB.Worksheets(1).Range("A4").CurrentRegion 'kopie van je data-gegevens staan in dit blad en lees je naar een array
If Not bOpen Then WB.Close xlNo
For Each c In ActiveWorkbook.Sheets("Samenvatting").UsedRange.Columns("C").SpecialCells(xlConstants) 'loop alle namen af in je C-kolom
If c.Row > 1 Then
sNaam = c.Value
dGeboorte = c.Offset(, -2).Value 'geboortedatum staat 2 kolommen naar links
dBegin = c.Offset(, 2).Value 'begindatum staat 1 kolom naar rechts
c.Offset(, -1).Value = "201500" 'schrijf alvast dez waarde weg naar je kostenplaats, 1 kolom naar links
For l = 1 To UBound(sn) 'loop alle gegevens in je array af
If sn(l, 2) = dGeboorte And sn(l, 5) <= dBegin And (dBegin <= sn(l, 6) Or IsEmpty(sn(l, 6))) And InStr(1, sn(l, 1), Trim(sNaam), 1) Then 'geboortedatum klopt, deel van de naam ook en valt binnen periode
Select Case sn(l, 8) 'onderzoek de mogelijke waarden van sn(l,10) kostenplaats
Case 403400 To 403470: c.Offset(, -1).Value = 434121 'ligt die hiertussen, dan schrijf je deze waarde weg
Case 403720 To 403730: c.Offset(, -1).Value = 434103 '2e mogelijkheid, andere waarde wegschrijven
Case 403740 To 403760: c.Offset(, -1).Value = 434101
Case 403800 To 403870: c.Offset(, -1).Value = 434111
Case 403900 To 403980: c.Offset(, -1).Value = 434135
Case 405700 To 405770: c.Offset(, -1).Value = 454101
Case 405800 To 405870: c.Offset(, -1).Value = 454111
Case 405900 To 405970: c.Offset(, -1).Value = 454121
Case 407640 To 407649: c.Offset(, -1).Value = 474141
Case 407660 To 407669: c.Offset(, -1).Value = 474101
Case 407730 To 407739: c.Offset(, -1).Value = 474103
Case 407790 To 407799: c.Offset(, -1).Value = 474105
Case 407810 To 407819: c.Offset(, -1).Value = 474111
Case 407820 To 407829: c.Offset(, -1).Value = 474131
Case 602140 To 602149: c.Offset(, -1).Value = 474121 'Langeberg 4&5 van RVE MCZN naar RVE Nijmegen
Case 407830 To 407839: c.Offset(, -1).Value = 622281 'brug eikstraat van RVE Nijmegen naar RVE MCZN
Case 601100 To 602139: c.Offset(, -1).Value = 622281
Case 602150 To 602599: c.Offset(, -1).Value = 622281
Case 603200 To 603980: c.Offset(, -1).Value = 622284
Case Else: c.Offset(, -1).Value = sn(l, 8) 'in alle andere gevallen, de oorspronkelijke waarde wegschrijven kolom kostenplaats
End Select
Exit For 'spring uit de loop
End If
Next
End If
Next
Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("E2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],2)"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E20000")
Range("E:E").Select
Columns("E:E").Select
Selection.Copy
Columns("D:D").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "CODE PRESTATIE"
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Cells.Select 'autofilter op tabblad samenvatting toegevoegd
Selection.autofilter
Cells.Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Samenvatting!R1C1:R1048576C6", Version:=xlPivotTableVersion14). _
CreatePivotTable TableDestination:="Blad1!R3C1", TableName:="Draaitabel1", _
DefaultVersion:=xlPivotTableVersion14
Sheets("Blad1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("Draaitabel1").PivotFields("KOSTENPLAATS")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("Draaitabel1").PivotFields("GEBOORTEDATUM")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("Draaitabel1").PivotFields("NAAM")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("Draaitabel1").PivotFields("CODE PRESTATIE")
.Orientation = xlRowField
.Position = 4
End With
With ActiveSheet.PivotTables("Draaitabel1").PivotFields("DATUM PRESTATIE")
.Orientation = xlRowField
.Position = 5
End With
ActiveSheet.PivotTables("Draaitabel1").AddDataField ActiveSheet.PivotTables( _
"Draaitabel1").PivotFields("KOSTEN"), "Aantal van KOSTEN", xlCount
ActiveSheet.PivotTables("Draaitabel1").PivotFields("KOSTENPLAATS").LayoutForm _
= xlTabular
ActiveSheet.PivotTables("Draaitabel1").PivotFields("KOSTENPLAATS"). _
LayoutBlankLine = True
With ActiveSheet.PivotTables("Draaitabel1").PivotFields("GEBOORTEDATUM")
.LayoutBlankLine = True
.LayoutForm = xlTabular
End With
ActiveSheet.PivotTables("Draaitabel1").PivotFields("NAAM").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("Draaitabel1").PivotFields("NAAM").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("Draaitabel1").PivotFields("CODE PRESTATIE").Subtotals _
= Array(False, False, False, False, False, False, False, False, False, False, False, False _
)
ActiveSheet.PivotTables("Draaitabel1").PivotFields("CODE PRESTATIE"). _
LayoutForm = xlTabular
With ActiveSheet.PivotTables("Draaitabel1").PivotFields("Aantal van KOSTEN")
.Caption = "Som van KOSTEN"
.Function = xlSum
End With
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.31496062992126)
.RightMargin = Application.InchesToPoints(0.31496062992126)
.TopMargin = Application.InchesToPoints(0.748031496062992)
.BottomMargin = Application.InchesToPoints(0.551181102362205)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
Sheets("Blad1").Select
Sheets("Blad1").Name = "Bijlage factuur"
With ActiveSheet.PivotTables("Draaitabel1").PivotFields("KOSTENPLAATS")
.PivotItems("(blank)").Visible = False
End With
Columns("F:F").Select
Selection.Style = "Currency"
End Sub