+ Reply to Thread
Results 1 to 12 of 12

Macro with relative reference does not copy a fixed location of cell data

  1. #1
    Registered User
    Join Date
    01-07-2022
    Location
    San Antonio, Texas
    MS-Off Ver
    Office 365 For Enterprise Subscription
    Posts
    9

    Macro with relative reference does not copy a fixed location of cell data

    I've tried for days to create a macro that inputs data copied from a fixed series of cells, into a row beginning at the cell I've selected, when the macro is executed (the cell data in the fixed location changes based on my input elsewhere in the spreadsheet). When it has finished, I would like for it to move to the next line automatically. The macro I create starts at the cell I've selected, but because it's relative, it will go to the next line of data to copy at the fixed location. Hard to explain so I've attached a spreadsheet with an example of what I would like to accomplish. Help!

    Thank you
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Macro with relative reference does not copy a fixed location of cell data

    Copy this event macro into the sheet's module. I'm using event BeforeRightClick because it will give you more control than BeforeDoubleClick or SelectionChange.
    If it doesn't do exacty what you are after you can use it as a starting point and adapt it to your needs.
    Please Login or Register  to view this content.
    Last edited by rollis13; 07-06-2022 at 05:43 PM.

  3. #3
    Registered User
    Join Date
    01-07-2022
    Location
    San Antonio, Texas
    MS-Off Ver
    Office 365 For Enterprise Subscription
    Posts
    9

    Re: Macro with relative reference does not copy a fixed location of cell data

    Thank you for your quick reply. I'm not experienced with macros and I'm sure I'm making a dumb entry error. When I enter the macro and attempt to execute it on the sample spreadsheet, it generates an error. See pic attached.
    Picture2.png

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Macro with relative reference does not copy a fixed location of cell data

    What is that "Sub Macro2()" doing there without its "End Sub" closure? Each macro has its own name and closes with "End Sub" and cannot be one inside the other.
    Also, you don't need to execute the macro, it triggers automatically when you double-click a cell in column A of the sheet in whose module you pasted it.
    Last edited by rollis13; 07-07-2022 at 04:10 PM.

  5. #5
    Registered User
    Join Date
    01-07-2022
    Location
    San Antonio, Texas
    MS-Off Ver
    Office 365 For Enterprise Subscription
    Posts
    9

    Re: Macro with relative reference does not copy a fixed location of cell data

    I'm sure your solution works rollis13, but despite researching the Option Explicit command and trying many ways to enter the code, I cannot make it work.
    I just don't know enough about macro writing and programming. I understand the "Sub Macro2()" and "End Sub" closure comment, but despite removing those lines,
    nothing I try works. Thank you for trying to provide a solution. If you can think of another way that may be more simplistic, please let me know.
    All I'm trying to do is populate a log I keep of my stock transactions. Rather than entering that data manually in each row under various column headings,
    which takes a lot of time, I'd like to just place the curser in column A, on whatever row I wish to begin the log entry and push a macro button. The macro
    executed would copy and paste the data from a fixed location to designated columns in the same row, starting with the cell I place the curser on. Then I would
    go to the next row and repeat the process. The fixed data copied would change based on a manual option that changes it and would not be a part of the macro.
    I wish I could explain it better. Thanks again for trying to help!

  6. #6
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Macro with relative reference does not copy a fixed location of cell data

    Attached you will find your file with this updated macro. Usage: choose a cell in column A and right-click, that's all.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-07-2022
    Location
    San Antonio, Texas
    MS-Off Ver
    Office 365 For Enterprise Subscription
    Posts
    9

    Re: Macro with relative reference does not copy a fixed location of cell data

    Thank you! It works. Now I'd like to transfer it to my log spreadsheet and modify it to copy the data and place it in the selected row. I found it on the Relative Reference Macro Question.xlsm when I opened the file by going to the Developer tab and selecting Visual Basic. Where would I find it or where would I insert the code on my actual log spreadsheet in order to modify it?

  8. #8
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Macro with relative reference does not copy a fixed location of cell data

    As said in post #2 and #4 the macro goes in the sheet's module so go to the VBE pane with keys Alt+F11, then on the left open your sheet in which this macro has to work and paste it in the right pane. Even faster, from the Excel pane, right-click the Tab of your sheet and choose "View Code" then paste the macro.
    Last edited by rollis13; 08-03-2022 at 04:42 PM.

  9. #9
    Registered User
    Join Date
    01-07-2022
    Location
    San Antonio, Texas
    MS-Off Ver
    Office 365 For Enterprise Subscription
    Posts
    9

    Re: Macro with relative reference does not copy a fixed location of cell data

    Thank you. I was able to modify the solution to my needs and the code worked well. I've learned a lot and I appreciate your help very much. One final question: How do I modify the code to make it copy only the text in the cells being copied? The current code copies the formulas to the individual destination columns/rows and writes over the column formatting as well -something I don't want to do. I need the formatting to remain intact in the destination columns/cells.
    Thanks again for your help.

  10. #10
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Macro with relative reference does not copy a fixed location of cell data

    Not sure if I correctly understood your request since there were no formulas in your example file. So I'll try to guess a solution:
    Please Login or Register  to view this content.
    Last edited by rollis13; 08-03-2022 at 05:01 PM.

  11. #11
    Registered User
    Join Date
    01-07-2022
    Location
    San Antonio, Texas
    MS-Off Ver
    Office 365 For Enterprise Subscription
    Posts
    9

    Re: Macro with relative reference does not copy a fixed location of cell data

    Perfect. Works great! I'll save so much time and effort entering data. Thanks for being patient with my questions. I'll close this thread as a sucess, soon.

  12. #12
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Macro with relative reference does not copy a fixed location of cell data

    Glad having been of some help.

+ 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] Is there a reference formula that will remain "fixed" to a cell location?
    By BryanHCR in forum Excel Formulas & Functions
    Replies: 45
    Last Post: 05-23-2019, 08:20 PM
  2. [SOLVED] Copy Paste Macro Relative to Button Location
    By Lacaycer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-21-2017, 01:21 PM
  3. Copy based on Relative Cell Reference and paste to Fixed cells
    By CDNcameron in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2014, 04:40 PM
  4. [SOLVED] Data validation list to run macro relative to cell location?
    By yukinosei in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-15-2014, 12:40 PM
  5. [SOLVED] R1C1 keep reference cell fixed in copy
    By ctosborne89 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-05-2012, 05:22 PM
  6. Relative cell reference in macro
    By hillbk in forum Excel General
    Replies: 15
    Last Post: 05-13-2009, 03:41 PM
  7. Macro-Copy&Paste Fixed Data Ranges Into Last Empty Cell of Specific Column
    By hailnorm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2009, 10:15 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