+ Reply to Thread
Results 1 to 3 of 3

Trying to figure out how to code a GOTO macro

Hybrid View

  1. #1
    Registered User
    Join Date
    08-16-2014
    Location
    Silicon Valley, CA
    MS-Off Ver
    2013
    Posts
    2

    Trying to figure out how to code a GOTO macro

    I'm a VBA novice, and have taken on a project that's currently beyond my skills, though I'm learning as fast as I can.

    My user has a small database in Excel (700 rows, 30 columns). The order # field (Column D) is a 5-digit number (there are no alpha characters). There is also a single-digit line-item # (Column E). The DB is sorted, with the primary key being order # and the secondary key being line-item #.

    The user wants a macro that will allow him to enter an order # and be taken to the first row in the database that matches that order #. He does not want to do this by using Excel's "Find" command -- he wants a macro.

    For example, if the order # he wants to go to is 13002, he would be satisfied with either:
    * Invoke the macro, then enter 13002 or
    * Enter 13002 in a specific cell in the worksheet and then invoke the macro

    In either case, the desired result is to activate the cell in Column D of the first row of the database where Order # = 13002.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Trying to figure out how to code a GOTO macro

    Would this work for you?
    Sub FindSomething()
        Dim uiValue As Variant
        
        uiValue = Application.InputBox("Enter an order #", Default:="13002", Type:=7)
        If uiValue = False And TypeName(uiValue) = "Boolean" Then Exit Sub: Rem cancel pressed
        
        On Error Resume Next
    
        With ActiveSheet.UsedRange
            Application.Goto .Find(What:=uiValue, After:=.Cells(.Rows.Count, .Columns.Count), LookIn:=xlValues, _
                LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=False)
        End With
    
        If Err Then Beep
        On Error GoTo 0
    End Sub
    Last edited by mikerickson; 08-17-2014 at 12:09 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    08-16-2014
    Location
    Silicon Valley, CA
    MS-Off Ver
    2013
    Posts
    2

    Re: Trying to figure out how to code a GOTO macro

    Thank you, Mike. This works, and I really appreciate you taking the time to help me.

+ 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] Skip this Macro Goto another - code required
    By keen2xl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2014, 03:16 PM
  2. Replies: 4
    Last Post: 02-03-2014, 08:05 AM
  3. GoTo code
    By RBI in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-27-2008, 09:46 AM
  4. GoTo or Run Code???
    By jkauffman in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-23-2008, 10:46 AM
  5. [SOLVED] Goto code
    By Bob in forum Excel General
    Replies: 4
    Last Post: 07-06-2006, 12:50 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