Consulting

Results 1 to 6 of 6

Thread: Filter data - date range and customer

  1. #1
    VBAX Regular
    Joined
    Jan 2021
    Posts
    16
    Location

    Cool Filter data - date range and customer

    Screen Shot 2021-01-27 at 20.50.30.jpg

    Hello


    According to the example above it should show records starting with ( like% ) the letters "tip" in the the specified "date range".

    Please tell me what's wrong in the code below:

    =====

    Option Explicit


    Sub data_controle()

    Dim lngStart As Long, lngEnd As Long

    Dim Repres As String

    lngStart = Range("b4").Value

    lngEnd = Range("c4").Value

    Range("c12:m2000").AutoFilter Field:=1, _
    Criteria1:=">=" & lngStart, _
    Operator:=xlAnd, _
    Criteria2:="<=" & lngEnd

    Range("C13", Range("C13").End(xlDown)).Sort Key1:=Range("C13"), Order1:=xlAscending, Header:=xlNo

    ActiveSheet.Range("$C$12:$M$2109").AutoFilter Field:=1, Criteria1:=">=" & lngStart, Operator:=xlAnd, Criteria2:="<=" & lngEnd

    ' the line below is not working ... ? - Repres

    ' ActiveSheet.Range("d4").AutoFilter Field:=2, Criteria1:=Repres & "*"



    End Sub

    =====

    Thank you
    Attached Images Attached Images
    Last edited by JonasB; 01-27-2021 at 04:53 PM.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    welcome to the forum.

    assign a value to repres variable.

    PHP Code:
    repres "tip" 
    and remove the filter before sort
    Last edited by mancubus; 01-27-2021 at 11:42 PM. Reason: last line added
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    my take on this:

    PHP Code:
    Sub vbax_68340()
        
    Dim LastRow As Long

        With ActiveSheet
            LastRow 
    = .Range("A" & .Rows.Count).End(xlUp).Row
            
    .Range("A12:M" LastRow).Sort Key1:=.Range("C13"), Order1:=xlAscendingHeader:=xlYes
            
    .Range("A12:M" LastRow).AutoFilter Field:=3Criteria1:=">=" CLng(Range("B4").Value), Operator:=xlAndCriteria2:="<=" CLng(Range("C4").Value)
            .
    Range("A12:M" LastRow).AutoFilter Field:=4Criteria1:="=Tip*"
        
    End With
    End Sub 
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Regular
    Joined
    Jan 2021
    Posts
    16
    Location
    Hello VBAX Guru

    Thank you. Almost perfect

    It searches online customers beginning with "Tip".

    .Range("A12:M" & LastRow).AutoFilter Field:=4, Criteria1:="=Tip*"

    ===

    I need to search any customer's name. So "d4" has to be adjusted

    .Range("A12:M" & LastRow).AutoFilter Field:=4, Criteria1:=d4

    Thank you

  5. #5
    VBAX Regular
    Joined
    Jan 2021
    Posts
    16
    Location
    I think I got it

    .Range("A12:M" & LastRow).AutoFilter Field:=2, Criteria1:=Range("d4") & "*"

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644

    Thumbs up

    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •