+ Reply to Thread
Results 1 to 3 of 3

Referring to Multiple Columns w/In Same Table in a Macro

  1. #1
    Registered User
    Join Date
    08-27-2014
    Location
    California, US
    MS-Off Ver
    Windows 2013, Mac 2011
    Posts
    2

    Referring to Multiple Columns w/In Same Table in a Macro

    I have some complicated excel formulas (nested conditionals, etc.) that I'm hoping to optimize w/VBA. I use tables because the data sets are dynamic. My goal is to be able to replace some complicated functions with macros that pull in table data into an array, execute the worksheet functions, and spit the results back out into the corresponding cell. My specific problem is that I'm curious if there's a way within VBA to refer to a column within the same record/row on the same table, in the same way that Access' version of SQL and basic Excel functions permit.

    In excel, one simple uses brackets and the @ sign, like this example of an excel formula in a column titled "Duplicate":

    =IF(AND(COUNTIFS([NAME],[@[NAME]],[LOCATION],[@[LOCATION]])>1,NOT([@[IGNORE_RECORD]]="NO")),"DUPLICATE","OK")

    Here, the table knows would know that for, say, a row representing a person named John Smith, it needs to look at the cell for "Ignore_Record," "Name," and "Location," in the same row as John Smith's name and populate the result in the column "Duplicate."

    My questions for you all are

    (1) whether there are any resources online or general tips about working with VBA arrays, listobjects, etc. to accomplish this same thing--ie, for relative references that allows the use of named ranges (I've found some solutions online using offsets, but these seem cumbersome and not scalable for future use, although I'd love any feedback if this impression is misguided)

    (2) if you think this is better achieved as function, rather than a macro incorporating worksheet functions?

    (Very green at VBA but decent at SQL and very proficient in non-VBA excel). Thank you!

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Referring to Multiple Columns w/In Same Table in a Macro

    I'm unclear on what you're trying to accomplish. If you can achieve the desired results with formulas, it's usually better/quicker than coding/running macros, especially if you have formulas that already work, and/or if you're not familiar with VBA. It's kind of like designing and building a tool to do something when you already have one in your garage that does it just fine. That being said, there's not much you can't do with VBA, whereas the things you can do with formulas are limited. You can even create your own custom functions and use them in formulas.
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Registered User
    Join Date
    08-27-2014
    Location
    California, US
    MS-Off Ver
    Windows 2013, Mac 2011
    Posts
    2

    Re: Referring to Multiple Columns w/In Same Table in a Macro

    I have a series of cascading conditionals that make the calculating take ages, due to the complexity of the functions, the number of them, and the number of records/rows. For example, one column might check if event X is type A or B, which another column relies on determine what date X must be completed on, which looks up who should be assigned to event X based on date from another table, etc., etc. I just can't figure out how to use the name of a column in a worksheet function instead of an absolute reference. I can't just use the @ sign in VBA, can I? Originally I had a macro that was copy/pasting the formulas instead of executing the functions directly but it was taking over 10 minutes for a CSE/array formula so I stopped it.

    I think I've maximized what I can do with basic excel (shunning the dreaded lookups in favor of index/match, dynamic ranges, setting calculations to update manually rather than automatically, etc.), and I was hoping to migrate them into VBA so I could just hit a button and wham, do it all at once and not have this monster of a workbook. The tool metaphor resonates. I could do it with Access in SQL, but that seemed like too large a tool, and the basic excel is a tad slow. I thought VBA/Excel might be something of a middle-ground, just right, goldilocks type of tool, and hoping to learn more VBA generally.

+ 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. Replies: 6
    Last Post: 12-20-2022, 02:32 PM
  2. How do I use an absolute reference in a formula when referring to a table
    By quantumag in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-17-2014, 02:01 PM
  3. [SOLVED] Convert table with multiple header columns into a pivotable table
    By jasonleewkd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2013, 03:20 AM
  4. sum column with restrictictions referring to other columns. How to do this?
    By zhoudiying in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-02-2011, 02:52 PM
  5. Referring to columns by number
    By SmithTS86 in forum Excel General
    Replies: 4
    Last Post: 04-20-2010, 10:59 AM

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