+ Reply to Thread
Results 1 to 5 of 5

Application.Match not recognising numerical strings

Hybrid View

  1. #1
    Registered User
    Join Date
    08-28-2013
    Location
    Brighton, England
    MS-Off Ver
    Excel 2007
    Posts
    14

    Application.Match not recognising numerical strings

    I have the following If function in an Excel VBA macro whic looks for the value of a defined variable within a column:

    Dim my_acc As String
    
    If IsError(Application.Match(my_acc, cb_range, 0)) Then
                cb_mvmt_ind = 0
                Else
                cb_mvmt_ind = 1
                End If
    However, the Application.Match function does not recognise cells that do contain the value of "my_acc" if the value is purely numerical. For example it will find "123456-78(GBP)" but will not find "12345678". I have tried declaring the variable "my_acc" as Integer, and have also tried just not declaring the variable at all but to no avail.

    Any ideas?

    Many thanks
    Last edited by Fotis1991; 10-29-2014 at 05:33 AM. Reason: PLS USE CODE TAGS AROUND YOUR CODES

  2. #2
    Forum Contributor
    Join Date
    08-10-2014
    Location
    Alberta
    MS-Off Ver
    2016
    Posts
    128

    Re: Application.Match not recognising numerical strings

    I am just an amateur but I think to use:

    Dim my_acc As String
    
    If IsError(Application.Match(CInt(my_acc), cb_range, 0)) Then
                cb_mvmt_ind = 0
                Else
                cb_mvmt_ind = 1
                End If
    End If
    Just a hint. Perhaps it will work.

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Application.Match not recognising numerical strings

    Are the 'integer' values in cb_range stored as numbers, or as text? With application.match, this matters.

    Try this instead:
    Dim c As Range
    Set c = cb_range.Find(my_acc)
    If Not c Is Nothing Then
        cb_mvmt_ind = 1
    Else
        cb_mvmt_ind = 0
    End If
    This should be less fussy about whether my_acc and cb_range are matching data types...
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Application.Match not recognising numerical strings

    Declare my_acc as Variant

    Dim my_acc As Variant


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  5. #5
    Registered User
    Join Date
    08-28-2013
    Location
    Brighton, England
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Application.Match not recognising numerical strings

    Bingo! Declaring the variable a s a Variant did the trick!

    Many thanks to all of you who replied so quickly - it is very much appreciated.

+ 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. Converting text strings into numerical values for multiple entries
    By exceln00bie113 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-13-2013, 10:55 AM
  2. [SOLVED] MATCH recognising "A*" in progress tracking sheet?
    By paulstuartbullock in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-27-2013, 07:01 AM
  3. [SOLVED] loop to match if shorter strings appears in longer strings
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2012, 08:07 PM
  4. Application.Match... or Application.WorksheetFunction.Match ...
    By SDruley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2011, 11:34 AM
  5. Replies: 2
    Last Post: 07-20-2008, 09:53 PM

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.6.0 RC 1