+ Reply to Thread
Results 1 to 3 of 3

Basic VBA IF statement

  1. #1
    Registered User
    Join Date
    04-09-2014
    Location
    Shanghai, China
    MS-Off Ver
    Excel 2010
    Posts
    1

    Basic VBA IF statement

    Hi All,

    I have a very basic vba IF statement problem.

    The situation is that I have a bunch of sheets in excel, every sheet = 1 client
    I want to create a search engine in an overview sheet, so you just have type the name of the client, press a vba button and it automatically goes to that sheet.
    The name of the client can only be found on its personal client page, so nowhere else.

    What i've done first is create a list with regular IF statements (non-vba), and the outcome is either "Goto" (the typed client name matches the client on sheet 1) or "Dontgo":

    Column N Column O
    Sheet 1: "Goto"
    Sheet 2: "Dontgo"
    Sheet 3: "Dontgo"
    Sheet 4: "Dontgo"
    etc.etc.

    Now I have the following vba but it always stops at sheet 1 cell D2:F2, regardless of cell "O3" having "Goto" or "Dontgo".

    Sub Search()

    If Range("O3").Value = "Goto" Then
    Application.Goto Sheets("1").Range("D2:F2"), True
    ElseIf Range("O4").Value = "Goto" Then
    Application.Goto Sheets("2").Range("D2:F2"), True
    ElseIf Range("O5").Value = "Goto" Then
    Application.Goto Sheets("3").Range("D2:F2"), True
    ElseIf Range("O6").Value = "Goto" Then
    Application.Goto Sheets("4").Range("D2:F2"), True

    Ive tried making the value in "O3" a hard value, no difference.
    Try Range.Select, no difference.

    Any help is appreciated!

    Jasper

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Basic VBA IF statement

    In your case since you have a sheet for each customer I would set sheet name = customer name and use a macro like this.

    Please Login or Register  to view this content.
    Alf

  3. #3
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Basic VBA IF statement

    Hello Jasper, and welcome to the forums

    One of the important things you will see as you progress is that it always an excellent idea to include in your request for assistance a sample workbook that shows exactly what you have and what you are expecting. Most of the contributors who provide suggestions / help are people with "regular day jobs" and are here as volunteers.

    It is sadly true that many people will simply pass a thread by if they have to spend time trying to build what they imagine you already have

    A bonus on top of getting people interested is that you often get some pretty good code returned that you can use to complete the resolution of your problem.

    I should also say, take a few minutes to read the forum rules (particularly in respect to posting code) to avoid a gentle rebuke from the moderators / senior experts. Unfortunately I don't have the ability to wrap your code so please do that as soon as you can.

    Now to your problem.

    Is it an option to have some form of extra worksheet (lets call it a "client register") as your first sheet in the workbook that contains a list of the customer names where the individual row is hyperlinked to the actual page??

    Just a thought that may be worth exploring. This can actually be set up manually (depending on the number of sheets OR how the customer sheets get created) pretty easily without the need to get into VBA at all

    Cheers

    Jmac1947

    1. Please consider clicking on the * Add Reputation if you think this post has helped you
    2. Mark your thread as SOLVED when question is resolved

+ 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. VBA - Pretty basic IF statement help needed
    By crayhons in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2013, 03:44 PM
  2. [SOLVED] more than your basic If statement.......
    By plamb in forum Excel General
    Replies: 3
    Last Post: 01-15-2013, 09:39 AM
  3. [SOLVED] Basic IF statement
    By Romwin in forum Excel General
    Replies: 7
    Last Post: 09-13-2012, 11:18 PM
  4. basic IF statement
    By mg03gq in forum Excel General
    Replies: 2
    Last Post: 07-17-2009, 04:20 PM
  5. If Statement - Basic
    By Portuga in forum Excel General
    Replies: 2
    Last Post: 01-23-2006, 02:10 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