+ Reply to Thread
Results 1 to 5 of 5

Amalgamating VBA codes into one

Hybrid View

  1. #1
    Registered User
    Join Date
    07-04-2008
    Location
    UK
    Posts
    2

    Amalgamating VBA codes into one

    Hi, I'm new to VBA is keen to learn.

    I'm currently using the codes below. Which uses Autfilter and sorts accordingly. I have many criterias which means I will need to create lots of codes for each criteria and run the code.

    Is is possible to amalgamate the code into one and select the criteria from a drop downmenu. (Enter Date and then select criteria eg. 03/07/08 - MEX)

    Or can someone guide me where to start?

    
    Sub ExceptionsMids()
    '
    
    '
    Dim MyDate As Date, StringDate As String
    With Sheets("Daily Sheet")
        StringDate = InputBox("Enter Date")
        If IsDate(StringDate) Then
            MyDate = DateValue(StringDate)
            .Range("D2") = MyDate
        Else
            MsgBox "Invalid Date"
            Exit Sub
        End If
        .Range("$B$4:$D$460").AutoFilter Field:=3, Criteria1:="MEX"
        Sheets("Daily Sheet").Select
    End With
    End Sub
    ----------------------------------
    
    Sub ExceptionsDays()
    '
    '
    Dim MyDate As Date, StringDate As String
    With Sheets("Daily Sheet")
        StringDate = InputBox("Enter Date")
        If IsDate(StringDate) Then
            MyDate = DateValue(StringDate)
            .Range("D2") = MyDate
        Else
            MsgBox "Invalid Date"
            Exit Sub
        End If
        .Range("$B$4:$D$460").AutoFilter Field:=3, Criteria1:="DEX"
        Sheets("Daily Sheet").Select
    End With
    End Sub
    Thanks

    Yogin
    Last edited by yogin2; 07-04-2008 at 04:00 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Welcome to the forum. Let's get started on the right foot:
    • Read our Forum Rules about thread titles, and then edit yours to be descriptive of your problem.
    • Wrap your code with Code Tags.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Thank you, Yogin.

    I don't think this does everything you want, but here's a start.
    Sub Exceptions()    '
        Dim sInp    As String
    
        Sheets("Daily Sheet").Select
        sInp = InputBox("Enter Date")
        If IsDate(sInp) Then
            Range("D2") = DateValue(sInp)
        Else
            MsgBox "Invalid Date"
            Exit Sub
        End If
    
        sInp = InputBox("Criteria?")
        If Len(sInp) = 0 Or sInp = "False" Then
            MsgBox "Invalid criteria"
            Exit Sub
        End If
    
        Range("$B$4:$D$460").AutoFilter Field:=3, Criteria1:=sInp
    End Sub

  4. #4
    Registered User
    Join Date
    07-04-2008
    Location
    UK
    Posts
    2
    Thank you for the quick reply shg,

    This is a great start.

    Yogin

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    You're very welcome. Post back if you need more help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1