+ Reply to Thread
Results 1 to 8 of 8

Macro does more than I recorded

  1. #1
    Registered User
    Join Date
    01-19-2011
    Location
    Moultonborough, NH
    MS-Off Ver
    Excel 2007
    Posts
    7

    Macro does more than I recorded

    I have cells like these:
    acvf121, dfrt231, juyt751, there are many more like this. All end in a 1.
    I recorded a macro to edit the cell to replace the final 1 with a 9. I used the first cell to record the macro. the keystrokes were: F2 (Edit), backspace, 9, Enter, up arrow. Stop recording.
    When I execute the macro on the second or any other cell, the result is "acvf129".
    How do I get it to just replace the last character in the cell?
    Thanks for your help.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro does more than I recorded

    Hi martinjr

    How about posting a sample that represents your actual data. Include the macro you recorded and what you'd like to see the results to be.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    01-19-2011
    Location
    Moultonborough, NH
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro does more than I recorded

    Here's a sampling of a Workbook I created with the type of data and formulas I'm working with.
    Sheet 1.
    Row 2= Date; Sample No; O2; N2;
    Row 3= 3/21/1994; 257; 3678; 19844;
    Row 4= 5/3/1994; 485; 400; 84052;
    (I've added a semicolon to separate cells.

    Sheet 2.

    Row 2= Data Line Number >; 6
    Row 3= Date; Sample No; O2; N2;
    Row 4= 3/21/1994; 257; 3678; 19844;
    this is what the Sheet 2 looks like.
    The formulas in the cells are,
    Row 4is: =INDIRECT("Sheet1!A"&$C$2); =INDIRECT("Sheet1!B"&$C$2); =INDIRECT("Sheet1!C"&$C$2); =INDIRECT("Sheet1!D"&$C$2)

    The Data in sheet 1 resides in rows 3 and 4.
    There is actually much more data than 2 rows.

    By entering a row number in cell C2 on Sheet 2, the data from that row on Sheet 1 appears on row 4 of Sheet 2.
    Not shown here is programming that uses the data in row 4 of Sheet 2.
    By stepping through the data this way, I can see the results of the programming (mostly graphical) over time but one date at a time.


    My next step was to create graphs of the data over multiple data points.
    To do this, I created a copy of row 4 of Sheet 2, onto rows 5 thru 9 (to give 6 data points.)
    The result is that rows 5 thru 9 have the exact same formula as row 4.

    Now I need to add a '-1' to the formula in each cell on row 5 and then add a '-2' on to each cell on row 6, etc.
    A Macro would have made this task much easier, but I could not get the Macro to work the way I needed it.
    I tried this with other formulas and with just plain data, but they all have the same problem.

    I don't know how to 'Write' a Macro so I use the 'Record Keystrokes' method.
    I selected cell A5 and recorded the following Macro "ADDneg1":

    Keystrokes were: click on cell E5, click Record Macro, name Macro "ADDneg1", click OK, press F2 (Edit), press left arrow, press -, press 1, press Enter, click Stop Recording.


    Now I go to cell F5, run Macro ADDneg1 and the result is the same as E5.

    Cell F5 should be; =INDIRECT("Sheet1!F"&$C$2-1)

    So the Macro is NOT following the keystrokes I entered, it is simply 'copying' cell E5.
    I don't know how to make this work the way I want it to.

    I don't know how to 'include' the Macro I've recorded.
    I hope this isn't too messy to deal with.

    Thank you for any insight you can provide.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro does more than I recorded

    Hello martinjr,

    You will get more responses to your post if you provide the workbook. Most people are not inclined to reproduce your workbook based on the data you have provided. This will also ensure you get the results you are looking for faster. Do yourself a favor and post the workbook.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    01-19-2011
    Location
    Moultonborough, NH
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro does more than I recorded

    When I tried to attach the workbook before, I clicked on the paper clip icon and it did nothing.
    Now it apparently let's me.
    here's the workbook.(I think).
    I uploaded the file.
    Attached Files Attached Files

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro does more than I recorded

    Hi martinjr

    Yes, your file did upload. It would be helpful (too me) if you would add data to Sheet3 that demonstrates your final desired results.

  7. #7
    Registered User
    Join Date
    01-19-2011
    Location
    Moultonborough, NH
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Macro does more than I recorded

    File with Sheet 3 uploaded.
    Attached Files Attached Files

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro does more than I recorded

    Hi martinjr

    Sorry, I sort of lost track of your issue. I've taken a different approach from yours in this code
    Please Login or Register  to view this content.
    But it appears to fill the data as requested (without formulas, if that's an issue). I see other problems but, first, see if this solution works. Let me know.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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