+ Reply to Thread
Results 1 to 5 of 5

Need to reference specific columns between multiple worksheets using VBA code

  1. #1
    Registered User
    Join Date
    03-20-2015
    Location
    Dallas
    MS-Off Ver
    MS Excel 2013
    Posts
    7

    Need to reference specific columns between multiple worksheets using VBA code

    Hello Experts,

    I am VBA self taught so I am probably overthinking this.

    I am trying to populate a pre-formatted table in one worksheet with data computed from a different worksheet using VBA and sumifs() function.

    The code works when the columns are referenced using for example C[31], C[2], etc. The problem here is that once i move to entering numbers in a different column in my table, all the references shift. I need the referenced columns to remain the same! I have been unsuccessful trying to reference the columns by the column headers (i must not know how to do this correctly). Below code should summarize the issue:

    Sub Test1_Dashboard_Calc()

    'This will populate first cell in pre-formatted table

    Please Login or Register  to view this content.
    With the above example, I expected that the referenced columns will be fixed but this is not the case ( C[58] is now referencing C[61])

    Please help. A solution using column headers directly would be ideal

    - Don't want to define any variables if possible
    Last edited by passerby08; 10-04-2019 at 03:18 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Need to reference specific columns between multiple worksheets using VBA code

    If you want absolute references, try using C58.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-20-2015
    Location
    Dallas
    MS-Off Ver
    MS Excel 2013
    Posts
    7

    Re: Need to reference specific columns between multiple worksheets using VBA code

    unfortunately it doesnt look like that works with the sumifs function when used with VBA
    Last edited by passerby08; 10-02-2019 at 06:21 PM.

  4. #4
    Registered User
    Join Date
    03-20-2015
    Location
    Dallas
    MS-Off Ver
    MS Excel 2013
    Posts
    7

    Re: Need to reference specific columns between multiple worksheets using VBA code

    I was able to figure out what the real issues was. When creating the code, i had recorded the macro which gave me the syntax I was using. when i looked at the actual formula that it translates to in the cell,its a slightly different format. Now this format by itself cant be put directly into VBA without an error. To fix the error I had to use double double quotes for searched criteria to work.
    Thank you.

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Need to reference specific columns between multiple worksheets using VBA code

    A way to avoid these kind op problems is to do as follows.
    Put your formula in the cell where you need it.
    Select the cell
    Tools, Macro, Record (OK where it suggests the Macro name)
    F2, Enter
    Now go and look at that Macro. The way it shows is the way it needs to be in a macro.

    You can change your Column Headers to numbers beforehand if you want to see RC notations.
    If you think you'll use it on regualr basis, put it in your Personal.xlsb
    Please Login or Register  to view this content.
    Could you be so kind and put all your code snippets between code tags in the future please.

+ 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: 4
    Last Post: 06-07-2019, 07:44 AM
  2. Replies: 5
    Last Post: 03-05-2018, 12:41 PM
  3. Searching multiple worksheets and displaying specific columns
    By whoosh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2017, 10:48 PM
  4. [SOLVED] VBA code that searches multiple worksheets in a workbk and returns specific data to sheet
    By SKooLZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-12-2015, 03:30 AM
  5. [SOLVED] Delete rows based on the value of two columns using VBA code - Multiple worksheets
    By OmniBlue in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2015, 04:24 PM
  6. Macro to copy specific columns from Multiple worksheets
    By Shellybelly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2015, 11:32 AM
  7. Replies: 1
    Last Post: 09-10-2012, 06:11 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