+ Reply to Thread
Results 1 to 7 of 7

VBA If with Like Operator not working

  1. #1
    Registered User
    Join Date
    04-05-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    29

    VBA If with Like Operator not working

    Hi I have the below bit of code but the If DateStr Like "*March*" Then MonthNumber = "/03/" Else MonthNumber = ""lines are not working, any ideas?

    I'm getting the output:
    12 March
    12


    I am hoping for:
    12 March
    12
    /03/

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,880

    Re: VBA If with Like Operator not working

    You either have to use an If...ElseIf.. statement, or a Select case
    Please Login or Register  to view this content.
    You can also simply the replace section with
    Please Login or Register  to view this content.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,836

    Re: VBA If with Like Operator not working

    Why have you opened this thread? Are you not being assisted with this in the commercial services forum?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  4. #4
    Registered User
    Join Date
    04-05-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    29

    Re: VBA If with Like Operator not working

    That's brilliant, thank you so much your help is greatly appreciated

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    As a VBA beginner starter :

    PHP Code: 
    Sub FixDateString()
      Const 
    "00"
        
    Dim M$(), DateStr$, V
            M 
    Split("January February March April May June July August September October November December")
            
    DateStr "12th March"
            
    Split(DateStr)
            
    V(0) = Format(Val(V(0)), F)
        If 
    UBound(V) > 0 Then
            V
    (1) = Application.Match(V(1), M0)
            If 
    IsError(V(1)) Then V(1) = Else V(1) = Format(V(1), F)
            If 
    UBound(V) > 1 Then If Not IsNumeric(V(2)) Then V(2) = F
        End 
    If
            
    Debug.Print DateStr"  ->  "Join(V"/")
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-08-2020 at 10:45 AM. Reason: optimization …

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,880

    Re: VBA If with Like Operator not working

    You're welcome & thanks for the feedback

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,836

    Re: VBA If with Like Operator not working

    Please answer the question in post #3. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Noty equal operator not working??
    By RustyNail in forum Excel General
    Replies: 4
    Last Post: 11-12-2018, 03:23 PM
  2. [SOLVED] "Less than or equal to" operator not working with dates
    By Plastik mac in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-15-2015, 09:14 AM
  3. "Less than or equal to" operator not working with dates
    By Plastik mac in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-15-2015, 02:39 AM
  4. [SOLVED] Comparison operator > not working
    By mottoth in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-01-2014, 09:23 AM
  5. Like Operator Not Working for Character List
    By Excel Guy 123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-14-2014, 01:47 PM
  6. Replies: 1
    Last Post: 08-23-2013, 05:45 PM
  7. OR Operator
    By Freddy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-17-2005, 02:06 PM

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