+ Reply to Thread
Results 1 to 2 of 2

How to refer to general columns

  1. #1
    Registered User
    Join Date
    06-19-2017
    Location
    Texas
    MS-Off Ver
    2013
    Posts
    33

    How to refer to general columns

    I have two examples of snippets of code:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    Both areas would be incorrect if I added another column into the spreadsheet. However, I would like to do this without having to change the code every time I add a new column. Any thoughts?

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to refer to general columns

    You cannot make VBA bullet proof to structural changes in the worksheet - protect the worksheet and ensure that anyone with password understands ramifications

    One trick is to use named ranges.
    Eg name cell A33 "TaxRate" and use Range("TaxRate") in the code -instead of Range("A33")
    When you insert 2 columns (A & B), A33 becomes C33
    Range("A33") gives wrong result but Range("TaxRate") still works because it's RefersTo range automatically changed to C33 when you inserted 2 columns

    The best advice is to nail the worksheet structure - get it right and stick to it - and avoid the temptation to tinker once the VBA is written. I prefer to add an extra worksheet linked to the nailed down one (still with its VBA working!) when someone asks for a new "flavour" of report
    Last edited by kev_; 08-02-2017 at 06:05 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

+ 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] How to refer to general rows instead of specific rows
    By mumair in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2017, 02:28 PM
  2. Automated Accounting System in posting to General Ledger from General Journal
    By Angelika_D15 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-31-2016, 02:08 AM
  3. Link a General Journal to General Ledger Debit or Credit balance
    By detoge in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-22-2015, 09:49 PM
  4. Replies: 1
    Last Post: 10-03-2013, 03:58 PM
  5. [SOLVED] Refer to several columns at once
    By vizzkid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2013, 05:34 AM
  6. [SOLVED] Formulas that refer to (several) other columns for arguments...
    By audreyglennette in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-31-2006, 11:10 PM
  7. [SOLVED] refer to columns
    By Cindy in forum Excel General
    Replies: 1
    Last Post: 01-20-2006, 05:55 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