+ Reply to Thread
Results 1 to 4 of 4

Faster way to code this

  1. #1
    jhahes
    Guest

    Faster way to code this

    I was just wondering if there is possibly another way to do this. With the code that i have it just seems to take forever...


    I am using a form and when you put in a number in textboxNumber


    the code goes to sheet1 and does the following

    Sheet1.activate
    Range("A2").select
    Do
    If csng(activecell) <> csng(textboxNumber.value) then
    activecell.offset(1,0).select
    End if

    Loop until csng(activecell) = csng(textboxNumber.value) or activecell.row = 5000

    activecell.offset(0,5).value = textboxOrderID
    activecell.offset(0,6).value = textboxItemDescription


    I would appreciate any ideas

  2. #2
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    You could use a find, eg:

    [a2:a5000].find(what:=textboxNumber.value, lookat:=xlwhole).select

    in place of the 'Do...Loop until'.

    Col

  3. #3
    Tom Ogilvy
    Guest

    RE: Faster way to code this

    Turn on the macro recorder. Select Column 1, Do edit=>Find then type in the
    number.

    Turn off the macro recorder and look at the recorded code

    Now modify this code to use the value in the textbox.

    from
    What:="1234"
    to
    What:=textboxNumber.value

    you can also modify it to check for a found value

    if application.Countif(Columns(1),textboxNumber.value) > 0 then
    ' modified recorded code
    else
    msgbox textboxNumber.Value & " is not in column 1"
    end if



    --
    Regards,
    Tom Ogilvy


    "jhahes" wrote:

    >
    > I was just wondering if there is possibly another way to do this. With
    > the code that i have it just seems to take forever...
    >
    >
    > I am using a form and when you put in a number in textboxNumber
    >
    >
    > the code goes to sheet1 and does the following
    >
    > Sheet1.activate
    > Range("A2").select
    > Do
    > If csng(activecell) <> csng(textboxNumber.value) then
    > activecell.offset(1,0).select
    > End if
    >
    > Loop until csng(activecell) = csng(textboxNumber.value) or
    > activecell.row = 5000
    >
    > activecell.offset(0,5).value = textboxOrderID
    > activecell.offset(0,6).value = textboxItemDescription
    >
    >
    > I would appreciate any ideas
    >
    >
    > --
    > jhahes
    > ------------------------------------------------------------------------
    > jhahes's Profile: http://www.excelforum.com/member.php...o&userid=23596
    > View this thread: http://www.excelforum.com/showthread...hreadid=558940
    >
    >


  4. #4
    jhahes
    Guest

    thank you for the help

    thanks for the responses colofnature, and tom. I used the macro recorder way and it works great.

    Thanks

+ 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