+ Reply to Thread
Results 1 to 8 of 8

Macro to edit a formula

  1. #1
    Registered User
    Join Date
    02-12-2018
    Location
    Texas, US
    MS-Off Ver
    2010
    Posts
    14

    Macro to edit a formula

    Hello!

    I have a unique problem which I know is going to be child's play for someone else.

    I have a monster of a macro, and in one part of it I have it copying the formula from a previous cell. So example would be, P6 is copying O6's formula which is a simple SUM formula. The part I need help on figuring how to edit the formula so it would move over 2 cells.

    To explain, P6 =SUM(Z57:Z2256) would be copied to O6, and would need to equal= SUM(AB57:AB2256)

    I attempted to use OFFSET, but it would move the O cell and not edit the actual equation.


    The reason why I am copying the cell to begin with is that the row number will be different on each Spreadsheet. In the example it is row 57, but in another workbook it would be 41, and so on.


    Thank you for any help.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Macro to edit a formula

    Are you copying from O to P, or P to O? Your question says both.

    Also, can you use Q6 to copy the formula to temporarily?

  3. #3
    Registered User
    Join Date
    02-12-2018
    Location
    Texas, US
    MS-Off Ver
    2010
    Posts
    14

    Re: Macro to edit a formula

    O to P.

    And I could use Q6 to copy it temporarily.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Macro to edit a formula

    In that case you should be able to do something like this:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Macro to edit a formula

    You could use code like t

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Registered User
    Join Date
    02-12-2018
    Location
    Texas, US
    MS-Off Ver
    2010
    Posts
    14

    Re: Macro to edit a formula

    The cell in question would actually be the first empty cell on the 6th row, so how would you put this as the range?

    Cells(6, emptyColumn2)

    emptyColumn2 = Cells(4, Columns.Count).End(xlToLeft).Column
    If emptyColumn2 > 0 Then
    emptyColumn2 = emptyColumn2 + 1
    End If


    I tried
    With Range("((Cells(6, emptyColumn2))")

    and With Range("(Cells(6, emptyColumn2)")

    but neither worked. Is this able to be a range?


    Thank you so much for your help.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Macro to edit a formula

    Are you looking for the first empty cell in row 6
    Please Login or Register  to view this content.
    or the cell to the right of the last filled cell in row 6
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-12-2018
    Location
    Texas, US
    MS-Off Ver
    2010
    Posts
    14

    Re: Macro to edit a formula

    It would first copy the previous cell's formula into the first empty cell in row 6. (In an example, it would copy O6 to P6 with P6 having been the empty cell). Then the macro would go inside the cell to the left of the new next empty column (P6) to edit the formula.

+ 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. Edit edit links macro to automate sheet selection
    By sds1126 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2015, 12:27 PM
  2. [SOLVED] Edit Macro to Auto Populate Formula's
    By Cansa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2013, 06:26 PM
  3. Help Using a Macro to edit a formula
    By missmea2005 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 09:09 AM
  4. Macro to Edit formula reference
    By Towz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2009, 04:21 AM
  5. Macro to edit formula
    By Tang123 in forum Excel General
    Replies: 2
    Last Post: 10-06-2005, 03:33 PM
  6. [SOLVED] Macro to edit a formula.
    By jimwood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2005, 11:05 AM
  7. How do I edit a formula as part of a macro?
    By Jacob Wood in forum Excel General
    Replies: 2
    Last Post: 01-31-2005, 05:17 PM

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