+ Reply to Thread
Results 1 to 3 of 3

Out of control IF Statement

  1. #1
    Registered User
    Join Date
    06-04-2017
    Location
    Austin, TX
    MS-Off Ver
    2010
    Posts
    21

    Out of control IF Statement

    I am trying to concatenate a number of cells in order to create a product title, Basic Data Text. These titles can contain up to eight cells based on a few conditions. There are two worksheets involved, Basic_Data_Text and Request. My IF statement is out of control and I need some help.

    I am an VBA newbie and often use the recorder to build things. This thing seems to have gotten out of hand so any help is greatly appreciated. As you can see my IF Statement is whacked out.

    Attached is my worksheets and a Word doc with some thoughts but things I am stumped on.

    Thank you
    Pablo
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Out of control IF Statement

    Two things:

    1. The code should be in its own module and not in the ThisWorkbook module. Go to the editor, select Insert -> Module then cut and paste the code into the new module.

    2. Provide a verbal specification of what you are trying to accomplish with the if statement. This will save us more than half the trouble. Otherwise the first step is to reverse engineer your intent. It would be a lot easier if you just told us .


    It looks like you are trying to get the VB code to enter a formula into a cell and that the reason for this is that part of the formula is to compare if the contents of a cell matches a value on a variable sized list. There are better ways of doing this and they do not involve VBA.

    If you want to test if a value is on a list of values then =ISNUMBER(MATCH(Value,List-of-Values,0)) will yield true if the value is on the list or false if it is not. Furthermore List-of-Values can be dynamic: make use of Excel Tables.

    If you took the information on the Request Sheet and made it into a Table then you could do several things. Tables know how big they are. You can eliminate rows 17 to 298 and don't worry about the data validation and formulas because tables also remember and copy down all this stuff automatically when you add a new row directly below the table.

    Then you can use formulas like: =ISNUMBER(MATCH(A21,Table1[Product Hierarchy],0)) as you add or delete data to the table, the formula will adjust to reference the exact number of rows it needs.

    Referencing Table parts is also possible in VBA. It makes the code a lot easier to understand and debug.

    Here is more information about tables: http://www.utteraccess.com/wiki/Tables_in_Excel.

    We'll await your specification as to what you are looking for in the IF statement.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Out of control IF Statement

    You can convert your formula section by section to VBA code, like so. This part:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Becomes code like this:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

+ 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] Any way to avoid hardcoding control name inside the control event procedure?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-24-2015, 07:50 PM
  2. Replies: 1
    Last Post: 02-15-2015, 08:45 PM
  3. [SOLVED] Call Form Control Option Button within an If statement
    By SonOfOdin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2012, 02:23 PM
  4. If then statement to control when the script runs
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2009, 06:42 PM
  5. IF statement to control formatting?
    By drdavidge in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-24-2008, 05:18 PM
  6. [SOLVED] Is there a VBA flow control statement that will ...
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-19-2006, 10:55 PM
  7. [SOLVED] Programatically control picture property of Image control
    By Brassman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-24-2005, 05:06 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