The idea is to make a planning tool, based on a "database":
- one row with dates, in the columns the needed transports,...
- want to search on today and copy the non-blanks in that column to another sheet "dashboard"
- want to copy the corresponding titles in the first columns of the "database" to the dashboard
Can't get it to work, searching around, and just don't get it, sorry. Novice in this... 2 questions:
- how to solve error 91
- how to dynamically select the right date (based on a loop through range) in a row with autofilter to get the data (non-blanks) in that column copied to another sheet?
Here's the code and the highlight where it gets stuck. If you want the file, let me know.
    Sub Transportplan()
'
' Transportplan Macro
'
' Sneltoets: Ctrl+Shift+T
    
    'ZET ALLES KLAAR VOOR NIEUWE PLANNING
    'Ga naar planningsoverzicht en delete vorige planning
    Sheets("NIEUW").Select
    Columns("B:G").Select
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Selection.ClearContents
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
        
    'Ga naar data tab
    Sheets("DATA").Select
    'Alle filters uitdoen
    ActiveSheet.ShowAllData
    'Activate search criteria in column
    ActiveSheet.Range("$A$4:$JN$196").AutoFilter Field:=5, Criteria1:=Array( _
        "Transport", "Transport INGEPAKT: Fase + (PALLETnrs)", _
        "Transport NIET ingepakt: Fase" & Chr(10) & "!!! RISICO NIET GELEVERD !!!", "Transport Retour" _
        ), Operator:=xlFilterValues
    
    '--------------------------------------------------------
    'START LOOP COPY PASTE SEQUENCE VOOR NIEUWE PLANNING
    
    '1. Choose the date in the tab "Datums voor macro"
    Sheets("Datums voor macro").Select
    'Loop through dates
    Dim rng As Range
    Dim cell As Range
    Set rng = Range("B4:B31")
    For Each cell In rng
         
        '------------------
        'Search the date in the DATA tab
        Sheets("DATA").Select
        Cells.Find(What:="cell", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
'HOW CAN I GET FIELD 21 dynamically changed if the date changes (in row 4)
   
        'If nothing that day, paste just the date
        ActiveSheet.Range("$A$4:$JN$1000").AutoFilter Field:=21, Criteria1:="<>"
        If (comboBox1.SelectedIndex = -1) Then
        'Go to planning and paste that day
        Sheets("NIEUW").Select
        Range("G1").Select
        ActiveCell.End(xlDown).Offset(1, 0).Select
        ActiveRange = cell.Value
        
            Else
'HOW CAN I GET FIELD 21 dynamically changed if the date changes (in row 4). I activated the macro through record and pressing Ctrl+F and pasting the date...
            ActiveSheet.Range("$A$4:$JN$196").AutoFilter Field:=21, Criteria1:="<>"
            Range(Selection, Selection.End(xlDown)).Select
            Application.CutCopyMode = False
            Selection.Copy
            'Go to planning and paste data
            Sheets("NIEUW").Select
            Range("G1").Select
            ActiveCell.End(xlDown).Offset(1, 0).Select
            ActiveSheet.Paste
            
            'Copy headers from DATA tab
            Sheets("DATA").Select
            Range("E4").Select
            Range(Selection, Selection.End(xlDown)).Select
            Range(Selection, Selection.End(xlToLeft)).Select
            Range(Selection, Selection.End(xlToLeft)).Select
            Application.CutCopyMode = False
            Selection.Copy
            'PASTE HEADERS in planning
            Sheets("NIEUW").Select
            'Search next empty cel to paste under previous data
            Range("B1").Select
            ActiveCell.End(xlDown).Offset(1, 0).Select
            ActiveSheet.Paste
            
            End If
        
        'END LOOP 1
        '-----------------------------------
        
        'RESTART LOOP
    Next cell
End Sub
 
    