+ Reply to Thread
Results 1 to 2 of 2

Unable to edit macro recording code to be a relative code.

  1. #1
    Registered User
    Join Date
    07-27-2014
    Location
    Ontario, Canada
    MS-Off Ver
    2010
    Posts
    3

    Unable to edit macro recording code to be a relative code.

    Hello,
    I tried recording a macro to automatically equate cells from a newly created workbook (also part of the macro) to another workbook to create a sort of a database.
    So "template 5 was created, and I manually made the cells on the "database" worksheet, equal to those some on template 3.
    Here is the code from that recording.

    Please Login or Register  to view this content.
    Notice how the code did absolute referencing for template 5. Is there a way to edit this code so that when a new worksheet is created through the macro, those cells from the new worksheet automatically are filled on the "database" worksheet?

    I dont know any VBA coding so I am trying to find a way to make this as simpler as possible.

    Appreciate any/ all help a lot!
    Last edited by JBeaucaire; 08-02-2014 at 10:43 AM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Unable to edit macro recording code to be a relative code.

    This isn't a VBA solution to the cell referencing question, it's a formula suggestion. You can use INDIRECT() formulas to construct cell references from text strings.

    For instance, if on my template sheet called "Template (5)" I wanted to see the value of cell B5, it would do this in my database sheet:

    1) In an empty row I'd add the new sheet name to column A
    2) Then I'd add INDIRECT() formulas on the same row grabbing cells using the column A sheet name.

    Please Login or Register  to view this content.
    This puts this formula in column B if the next row (NR) were row 5:
    =INDIRECT("'" & A5 & "'!B5")

    So just expand on that. This way, you need only grab the new sheet name once, add it to column A, then drop in the same INDIRECT() links on the same row to create your links.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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. change macro code generated through recording
    By abraham30 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2013, 02:38 AM
  2. [SOLVED] Instances where macro recording cannot be used to generate code
    By SynGC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2012, 04:55 AM
  3. Cleaning up the code after recording a macro.
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-01-2010, 02:30 PM
  4. Simplify VBA code for autofilter from Macro recording
    By miners in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-27-2009, 09:58 PM
  5. VBA Code vs Macro Recording code
    By JoeSharp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-10-2007, 11:17 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