Results 1 to 2 of 2

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

Threaded View

holaitsme Unable to edit macro... 08-02-2014, 10:05 AM
JBeaucaire Re: Unable to edit macro... 08-02-2014, 10:51 AM
  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.

    Sub Populatedata()
    '
    ' Populatedata Macro
    '
    ' Keyboard Shortcut: Ctrl+r
    '
        Sheets("Template").Select
        Sheets("Template").Copy After:=Sheets(6)
        Sheets("Database").Select
        ActiveCell.Offset(-6, -2).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[-1]C[4]"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!RC[3]"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[1]C[2]"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[6]C"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[6]C"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[6]C"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[8]C[-3]"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[8]C[-3]"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[8]C[-3]"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[10]C[-6]"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[10]C[-6]"
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveCell.FormulaR1C1 = "='Template (5)'!R[10]C[-6]"
        ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveWindow.SmallScroll Down:=-3
    End Sub
    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.

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