Ga naar inhoud

bakerman

Lid
  • Items

    378
  • Registratiedatum

  • Laatst bezocht

Berichten die geplaatst zijn door bakerman

  1. Kleine aanpassing.

    Sub SortBirthdays()
    Application.ScreenUpdating = False
    Dim lRow As Long
    With Blad1
        lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Range("Z2:Z" & lRow).FormulaR1C1 = "=TEXT(RC3,""MMDD"")"
        .Range("A2:Z" & lRow).Sort .Range("Z2"), xlAscending, , , , , , xlNo
        .Range("Z2:Z" & lRow).Clear
    End With
    Application.ScreenUpdating = True
    End Sub

    en dan is dit het resultaat.

     

    Knipsel.PNG

  2. Deze sorteert op maand en dag. Je kan de dag en maandkolom zonder probleem verwijderen.

    Sub SortBirthdays()
    Application.ScreenUpdating = False
    Dim lRow As Long
    With Blad1
        lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Range("Z2:Z" & lRow).FormulaR1C1 = "=TEXT(RC3,""MMDD"")"
        .Range("A2:Z" & lRow).Sort .Range("Z2"), xlAscending, , , , , , xlYes
        .Range("Z2:Z" & lRow).Clear
    End With
    Application.ScreenUpdating = True
    End Sub

     

  3. Had 'm om te testen op vandaag gezet en vergeten terug te zetten.

    Private Sub Workbook_Open()
    With Sheets(1)
        For i = 2 To .Range("a1").End(xlDown).Row
            If (Day(CDate(.Range("c" & i).Value)) - Day(Date) = 1) * (Month(CDate(.Range("c" & i).Value)) - Month(Date) = 0) Then
                msg = msg & .Range("b" & i).Value & vbLf & vbLf
            End If
        Next i
    End With
    If msg <> vbNullString Then MsgBox msg & vbLf & "is (zijn) morgen jarig.", vbInformation, "Verjaardagen."
    End Sub
  4. I.p.v. 3X op OK te moeten drukken.

    Private Sub Workbook_Open()
    With Sheets(1)
        For i = 2 To .Range("a1").End(xlDown).Row
            If (Day(CDate(.Range("c" & i).Value)) - Day(Date) = 0) * (Month(CDate(.Range("c" & i).Value)) - Month(Date) = 0) Then
                msg = msg & .Range("b" & i).Value & vbLf & vbLf
            End If
        Next i
    End With
    If msg <> vbNullString Then MsgBox msg & vbLf & "is (zijn) morgen jarig.", vbInformation, "Verjaardagen."
    End Sub

     

  5. Deze heb ik je ook al eens eerder gegeven.
     

    Sub UpdateBestanden()
    
    Dim FilePath$, Row&, Column&, Address$
    'change constants & FilePath below to suit
          '***************************************
         
          Const SheetName$ = "Personalia"
          Address = Cells(11, 2).Address
          FilePath = "D:\Test2\"
          '***************************************
        With CreateObject("scripting.filesystemobject").getfolder(FilePath)
            For Each fl In .Files
                If Right(fl.Name, 5) = ".xlsx" Then
                    Cells(Rows.Count, 1).End(xlUp).Offset(1) = fl.Name
                    Filename = fl.Name
                    Cells(Rows.Count, 1).End(xlUp).Offset(0, 1) = GetData(FilePath, Filename, SheetName, Address)
                    Columns.AutoFit
                End If
            Next
        End With
    End Sub
    
    Private Function GetData(path, file, sheet, Address)
          Dim Data$
          Data = "'" & path & "[" & file & "]" & sheet & "'!" & _
                Range(Address).Range("A1").Address(, , xlR1C1)
          GetData = ExecuteExcel4Macro(Data)
    End Function

     

  6. Een andere oplossing. :)

    Sub tst()
        Dim dic As Object, sn, i As Long
        sn = Blad2.Cells(1).CurrentRegion.Value
        Set dic = CreateObject("scripting.dictionary")
        For i = 2 To UBound(sn)
            If Not dic.exists(sn(i, 1)) Then
                dic.Add sn(i, 1), sn(i, 2)
                Else: dic.Item(sn(i, 1)) = dic.Item(sn(i, 1)) + sn(i, 2)
            End If
        Next
        sn = Blad1.Cells(1).CurrentRegion.Resize(, 3).Value
        For i = 2 To UBound(sn)
            If dic.exists(sn(i, 2)) Then
                sn(i, 3) = dic.Item(sn(i, 2))
            Else: sn(i, 3) = 0
            End If
        Next
        Blad1.Cells(1).Resize(UBound(sn), 3) = sn
    End Sub

     

  7. Wijzig de Const wDir in de correcte map waar alle bestanden staan.

    Sub ConsolidateAll()
        Dim rsCon As Object, rsData As Object, sFileName As String
        Dim Prov As String, ExProp As String, resarr ', wDir As String
        Const wDir = "D:\Test2\"
        Prov = IIf(Val(Application.Version) < 12, "Microsoft.Jet.OLEDB.4.0", "Microsoft.ACE.OLEDB.12.0")
        ExProp = IIf(Val(Application.Version) < 12, "8.0", "12.0")
        Sheets(1).Cells(1).CurrentRegion.Offset(1).ClearContents
        sFileName = Dir(wDir & "*.xlsx")
        Do While sFileName <> ""
            If sFileName <> ThisWorkbook.Name Then
                Set rsCon = CreateObject("ADODB.Connection"): Set rsData = CreateObject("ADODB.Recordset")
                rsCon.Open "Provider=" & Prov & ";Data Source=" & wDir & sFileName & _
                                ";Extended Properties=""Excel " & ExProp & ";HDR=No"";"
                rsData.Open "SELECT * FROM [Personalia$B2:B14];", rsCon, 0, 1, 1
                If Not rsData.EOF Then
                    resarr = rsData.GetRows
                End If
                Sheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(UBound(resarr, 1) + 1, UBound(resarr, 2) + 1) = resarr
                sFileName = Dir: rsData.Close: Set rsData = Nothing: rsCon.Close: Set rsCon = Nothing
            End If
        Loop
    End Sub

     

    janlazeure.xlsm

  8. Sub afdrukken()
        Application.ScreenUpdating = False
        With Sheets(1)
            .PageSetup.Orientation = xlPortrait
            .Cells(1).CurrentRegion.Sort .Range("L1"), xlAscending, , , , , , xlYes
            .Range("A:A,C:K").EntireColumn.Hidden = True
            .PrintPreview 'PrintOut
            .Range("A:A,C:K").EntireColumn.Hidden = False
            .Cells(1).CurrentRegion.Sort .Range("B1"), xlAscending, , , , , , xlYes
        End With
        Application.ScreenUpdating = True
    End Sub

     

  9. Sub afdrukken()
        Application.ScreenUpdating = False
        With Sheets(1)
            .PageSetup.Orientation = xlPortrait
            .Cells(1).CurrentRegion.Sort .Range("K1"), xlAscending, , , , , , xlYes
            .Range("A:A,C:J").EntireColumn.Hidden = True
            .PrintPreview 'PrintOut
            .Range("A:A,C:J").EntireColumn.Hidden = False
            .Cells(1).CurrentRegion.Sort .Range("B1"), xlAscending, , , , , , xlYes
        End With
        Application.ScreenUpdating = True
    End Sub

     

  10. Vermijd het gebruik van overbodige variabelen.

    Sub afdrukken2()
        Application.ScreenUpdating = False
        With Sheets(1)
            .PageSetup.Orientation = xlPortrait
            .Cells(1).CurrentRegion.Sort Key1:=.Range("I1"), Order1:=xlAscending, Header:=xlYes
            .Columns("B:H").EntireColumn.Hidden = True
            .PrintPreview 'PrintOut
            .Columns("B:H").EntireColumn.Hidden = False
            .Cells(1).CurrentRegion.Sort Key1:=.Range("A1"), Order1:=xlAscending, Header:=xlYes
        End With
        Application.ScreenUpdating = True
    End Sub

     

  11. Verbeterde code.

    Sub SelectiefPrinten()
        With Blad2
            .Range("H2") = Application.InputBox("Geef het maandnummer op", , , , , , , 1)
            .Cells(1).CurrentRegion.Offset(1).ClearContents
            Blad1.Cells(1).CurrentRegion.AdvancedFilter 2, .Range("G1:H2"), .Range("A1:B1")
            With .Cells(1).CurrentRegion
                .Columns.AutoFit
                .PrintPreview
            End With
        End With
    End Sub

     

  12. Vervang dan de huidige code eens door deze.

    Sub tst()
    Dim col As New Collection
    Dim myarr
    With Sheets("Blad1")
        sn = .Cells(1, 2).CurrentRegion.Value
    End With
    With col
        For i = 2 To UBound(sn, 2) Step 2
            For ii = 2 To UBound(sn)
                If sn(ii, i) <> vbNullString Then .Add Array(sn(ii, i + 1), sn(ii, i)), sn(ii, i + 1)
            Next
        Next
        ReDim myarr(1 To .Count, 1 To 2)
    End With
    x = 1
    For Each i In col
        myarr(x, 1) = i(1): myarr(x, 2) = i(0)
        x = x + 1
    Next
    With Sheets("Blad1").Cells(20, 1)
        .CurrentRegion.ClearContents
        .Resize(UBound(myarr), 2) = myarr
    End With
    End Sub

     

  13. @alpha

    Het is een knop uit de collectie Formulierbesturingselementen die gebruikt is.

     

    @pd123

    Draai jij toevallig De Mac-versie van Office ?

    Indien Ja dan zal Dictionary niet werken en moeten we overschakelen naar een Collection.

    Indien Neen dan moet je in de Opties voor Excel in het VertrouwensCentrum je instellingen nakijken dat je toegang verleent aan het Objectmodel.

  14. Sub UpdateBestanden()
    
    Dim FilePath$, Row&, Column&, Address$
    'change constants & FilePath below to suit
          '***************************************
         
          Const SheetName$ = "Blad1"
          Address = Cells(1).Address
          FilePath = "D:\Test2\"
          '***************************************
        With CreateObject("scripting.filesystemobject").getfolder(FilePath)
            For Each fl In .Files
                If Right(fl.Name, 5) = ".xlsx" Then
                    Cells(Rows.Count, 1).End(xlUp).Offset(1) = fl.Name
                    Filename = fl.Name
                    Cells(Rows.Count, 1).End(xlUp).Offset(0, 1) = GetData(FilePath, Filename, SheetName, Address)
                    Columns.AutoFit
                End If
            Next
        End With
    End Sub
    
    Private Function GetData(path, file, sheet, Address)
          Dim Data$
          Data = "'" & path & "[" & file & "]" & sheet & "'!" & _
                Range(Address).Range("A1").Address(, , xlR1C1)
          GetData = ExecuteExcel4Macro(Data)
    End Function

     

  15. Weet niet hoeveel ervaring je hebt met VBA maar deze doet wat je vraagt.

    Sub tst()
    With Sheets("Blad1")
        sn = .Cells(1, 2).CurrentRegion.Value
    End With
    With CreateObject("scripting.dictionary")
        For i = 2 To UBound(sn, 2) Step 2
            For ii = 2 To UBound(sn)
                If sn(ii, i) <> vbNullString Then
                    .Add sn(ii, i + 1), sn(ii, i)
                    x = x + 1
                End If
            Next
        Next
        Sheets("Blad1").Cells(20, 1).Resize(x, 2) = Application.Transpose(Array(.items, .keys))
    End With
    End Sub

    Heb je vragen laat maar iets weten.

×
×
  • Nieuwe aanmaken...

Belangrijke informatie

We hebben cookies geplaatst op je toestel om deze website voor jou beter te kunnen maken. Je kunt de cookie instellingen aanpassen, anders gaan we er van uit dat het goed is om verder te gaan.