+ Reply to Thread
Results 1 to 5 of 5

HELP! Number length macro

Hybrid View

Guest HELP! Number length macro 03-24-2006, 01:15 PM
Guest RE: HELP! Number length macro 03-24-2006, 01:50 PM
Guest RE: HELP! Number length macro 04-02-2006, 02:45 PM
Guest RE: HELP! Number length macro 04-05-2006, 05:10 AM
Guest Re: HELP! Number length macro 03-24-2006, 01:55 PM
  1. #1
    Jas
    Guest

    HELP! Number length macro

    Hi,

    I need a macro that will take the input from cell A1 (numbers) and will keep
    dropping a digit until it finds a match on another spreadsheet (assume its
    all in column A:A). So, I need it to do the following
    Cell A1 "12345"
    A2 "1234"
    A3 "123"
    A4 "12" and it needs to stop at 2 digits.

    The numbers in cells A2-A4 are checked in Sheet2 and if there is a match
    then I need a message box saying "Found", or something.

    How can I do this?
    Thanks
    Jas

  2. #2
    Tom Ogilvy
    Guest

    RE: HELP! Number length macro

    Sub Checkmatches()
    Dim i as Long, s as String
    Dim res as Variant
    s = Range("A1").Value
    for i = len(s) to 1 step -1
    res = Application.Match(clng(s),Worksheets("Sheet2").Columns(1),0)
    if not iserror(res) then
    msgbox "found " & s & " at row " & res
    exit for
    else
    if len(s) > 1
    s = left(s,len(s)-1)
    end if
    end if
    Next i
    End Sub

    --
    Regards,
    Tom Ogilvy


    "Jas" wrote:

    > Hi,
    >
    > I need a macro that will take the input from cell A1 (numbers) and will keep
    > dropping a digit until it finds a match on another spreadsheet (assume its
    > all in column A:A). So, I need it to do the following
    > Cell A1 "12345"
    > A2 "1234"
    > A3 "123"
    > A4 "12" and it needs to stop at 2 digits.
    >
    > The numbers in cells A2-A4 are checked in Sheet2 and if there is a match
    > then I need a message box saying "Found", or something.
    >
    > How can I do this?
    > Thanks
    > Jas


  3. #3
    Jas
    Guest

    RE: HELP! Number length macro

    That works perfectly! Thankyou!!

    "Tom Ogilvy" wrote:

    > Sub Checkmatches()
    > Dim i as Long, s as String
    > Dim res as Variant
    > s = Range("A1").Value
    > for i = len(s) to 1 step -1
    > res = Application.Match(clng(s),Worksheets("Sheet2").Columns(1),0)
    > if not iserror(res) then
    > msgbox "found " & s & " at row " & res
    > exit for
    > else
    > if len(s) > 1
    > s = left(s,len(s)-1)
    > end if
    > end if
    > Next i
    > End Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Jas" wrote:
    >
    > > Hi,
    > >
    > > I need a macro that will take the input from cell A1 (numbers) and will keep
    > > dropping a digit until it finds a match on another spreadsheet (assume its
    > > all in column A:A). So, I need it to do the following
    > > Cell A1 "12345"
    > > A2 "1234"
    > > A3 "123"
    > > A4 "12" and it needs to stop at 2 digits.
    > >
    > > The numbers in cells A2-A4 are checked in Sheet2 and if there is a match
    > > then I need a message box saying "Found", or something.
    > >
    > > How can I do this?
    > > Thanks
    > > Jas


  4. #4
    Jas
    Guest

    RE: HELP! Number length macro

    Hi Tom,

    How would I loop through that statement? Ie do the check for range A1:A10
    if I had a list of numbers to check?

    Thanks!
    Jas

    "Tom Ogilvy" wrote:

    > Sub Checkmatches()
    > Dim i as Long, s as String
    > Dim res as Variant
    > s = Range("A1").Value
    > for i = len(s) to 1 step -1
    > res = Application.Match(clng(s),Worksheets("Sheet2").Columns(1),0)
    > if not iserror(res) then
    > msgbox "found " & s & " at row " & res
    > exit for
    > else
    > if len(s) > 1
    > s = left(s,len(s)-1)
    > end if
    > end if
    > Next i
    > End Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Jas" wrote:
    >
    > > Hi,
    > >
    > > I need a macro that will take the input from cell A1 (numbers) and will keep
    > > dropping a digit until it finds a match on another spreadsheet (assume its
    > > all in column A:A). So, I need it to do the following
    > > Cell A1 "12345"
    > > A2 "1234"
    > > A3 "123"
    > > A4 "12" and it needs to stop at 2 digits.
    > >
    > > The numbers in cells A2-A4 are checked in Sheet2 and if there is a match
    > > then I need a message box saying "Found", or something.
    > >
    > > How can I do this?
    > > Thanks
    > > Jas


  5. #5
    Don Guillett
    Guest

    Re: HELP! Number length macro

    something like this?

    Sub findbestmatch()
    On Error Resume Next
    With Sheets("sheet10").Columns(1)
    x = .Find("12345", lookat:=xlWhole).Address
    x = .Find("1234", lookat:=xlWhole).Address
    x = .Find("123", lookat:=xlWhole).Address
    x = .Find("12", lookat:=xlWhole).Address
    End With
    MsgBox x
    End Sub

    --
    Don Guillett
    SalesAid Software
    dguillett1@austin.rr.com
    "Jas" <Jas@discussions.microsoft.com> wrote in message
    news:C3BB6DEC-D2AC-4B99-8D03-110DE15DEA10@microsoft.com...
    > Hi,
    >
    > I need a macro that will take the input from cell A1 (numbers) and will
    > keep
    > dropping a digit until it finds a match on another spreadsheet (assume its
    > all in column A:A). So, I need it to do the following
    > Cell A1 "12345"
    > A2 "1234"
    > A3 "123"
    > A4 "12" and it needs to stop at 2 digits.
    >
    > The numbers in cells A2-A4 are checked in Sheet2 and if there is a match
    > then I need a message box saying "Found", or something.
    >
    > How can I do this?
    > Thanks
    > Jas




+ 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