+ Reply to Thread
Results 1 to 8 of 8

Thread: dual textbox actions

  1. #1
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    152

    Post dual textbox actions

    Im useing a piece of code (below) which take the mid values of a string from one text box and generates it into differant Month format (09_Sep).
    On a seperate tab on the same user form I have a second text box which will have differant values entered into it.
    Is there anyway that I can use the below pice of code for both txt boxes?

    Strings 'ThisWeekDate' & 'LendingMonth' are defined earlier in the code.
    Thanks

    
    '''''''''''''''''''''
    '''Re-Format Month'''
    '''''''''''''''''''''
    Sub ThisMonth()
    test = Mid(ThisWeekDate, 4, 2)
    or test = LendingMonth<------------------------- Attemp
    
        Select Case Mid(ThisWeekDate, 4, 2)
            Case "01":      GblMonth = "01_Jan"
            Case "02":      GblMonth = "02_Feb"
            Case "03":      GblMonth = "03_Mar"
            Case "04":      GblMonth = "04_Apr"
            Case "05":      GblMonth = "05_May"
            Case "06":      GblMonth = "06_Jun"
            Case "07":      GblMonth = "07_Jul"
            Case "08":      GblMonth = "08_Aug"
            Case "09":      GblMonth = "09_Sep"
            Case "10":      GblMonth = "10_Oct"
            Case "11":      GblMonth = "11_Nov"
            Case "12":      GblMonth = "12_Dec"
        End Select
    End Sub

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: dual textbox actions

    create a function rather than a subroutine.
    The function takes an argument and returns a value

    Sub Test()
        
        GblMonth = ThisMonth(ThisWeekDate)
        
        GblMonth = ThisMonth(LendingMonth)
        
        
    End Sub
    
    '''''''''''''''''''''
    '''Re-Format Month'''
    '''''''''''''''''''''
    Function ThisMonth(Arg)
    
        Dim ReturnValue
        
        Select Case Mid(Arg, 4, 2)
            Case "01":      ReturnValue = "01_Jan"
            Case "02":      ReturnValue = "02_Feb"
            Case "03":      ReturnValue = "03_Mar"
            Case "04":      ReturnValue = "04_Apr"
            Case "05":      ReturnValue = "05_May"
            Case "06":      ReturnValue = "06_Jun"
            Case "07":      ReturnValue = "07_Jul"
            Case "08":      ReturnValue = "08_Aug"
            Case "09":      ReturnValue = "09_Sep"
            Case "10":      ReturnValue = "10_Oct"
            Case "11":      ReturnValue = "11_Nov"
            Case "12":      ReturnValue = "12_Dec"
        End Select
        
        ThisMonth = ReturnValue
        
    End Function
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: dual textbox actions

    Function ThisMonth(c01)
      ThisMonth=format(mid(c01,4,2),"00_") & format(dateserial(2010,val(mid(c01,4,2)),1),"mm")
    End Sub
    or
    Function ThisMonth(c01)
      ThisMonth=format(mid(c01,4,2),"00_") & monthname(mid(c01,4,2))
    End Sub
    Last edited by snb; 09-10-2010 at 11:11 AM.



  4. #4
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    152

    Re: dual textbox actions

    Hey Andy,
    The problum is that the strings are in differant Date Formats.
    Thisweek date = dd-mm-yyyy
    LendingMonth = mm
    Any ideas??

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: dual textbox actions

    Where in your original post did it say that?
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    152

    Re: dual textbox actions

    Hey Andy
    "a second text box which will have differant values entered into it" - Apologies, I see how that can be misunderstood as a differant date (in the same format). I should have made that clearer.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: dual textbox actions

    Function ThisMonth(Arg)
    if len(Arg) =2 then
        ThisMonth = format(Datevalue("01-" & Arg & "-2010"),"mm_mmm")
    else
       ThisMonth = format(datevalue(Arg),"mm_mmm") 
    End if
    End Function
    Cheers
    Andy
    www.andypope.info

  8. #8
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    152

    Re: dual textbox actions

    Cheers for that Andy

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0