Consulting

Results 1 to 8 of 8

Thread: find substring and display message box

  1. #1
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    5
    Location

    Cool find substring and display message box

    I have a set of dates in excel that I need to be able to loop through however the starting dates are not always on the first and so I need to be able to determine the day but not the year or month. What I have is not working

    checkDates (ActiveCell.Value)
    Please note that there is a difference in the case statements simply because I am trying to get the first one to work and then I will modify the rest based off of that one.

    Sub checkDates(day As String)
    
    Dim mth As String
    Dim dy As String
    Dim yr As String
    
    'MsgBox day
    
        Select Case day
            Case1 "/1/" Like "*" & day & "*":
                MsgBox "day one"
            Case day Like "*/2/*"
            Case day Like "*/3/*":
            Case day Like "*/4/*":
            Case day Like "*/5/*":
            Case day Like "*/6/*":
            Case day Like "*/7/*":
            
            Case Else
            MsgBox "test"
        End Select
    Thank you

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Why not just extract the day using the Day function?

  3. #3
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    5
    Location
    Quote Originally Posted by Norie
    Why not just extract the day using the Day function?
    Probably because I am not aware of that one or how it works...do mind helping me with some examples.

  4. #4
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    5
    Location
    *bump

  5. #5
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Well if you have a date you can easily extract the day.

    For example:
    [vba]
    Msgbox Day(Date)
    [/vba]

  6. #6
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    5
    Location
    well that won't compile in my version of Office(2003)

    and there is nothing in the help file about it.

  7. #7
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Well the reason it won't compile could be because you've declared a variable called day.

    And since Day is a VBA function that's not a good idea.

  8. #8
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    5
    Location
    and I knew that too..thanx.

    I ended up just using DatePart instead.

Posting Permissions

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