+ Reply to Thread
Results 1 to 5 of 5

Macro to change only part of a formula to absolute

  1. #1
    Registered User
    Join Date
    09-29-2014
    Location
    Baltimore
    MS-Off Ver
    2010
    Posts
    19

    Macro to change only part of a formula to absolute

    I'm trying to make a macro where I can insert a formula with both relative and absolute referencing (e.g. =F$58+F59). The thing is, I want the absolute value to be based off of where I started the macro so that I can then use the pull down function to automatically fill in the rest of the values. For example, if I started in A6, I want the formula to say something like =F$6 + G6 and when I pull it down and if I started in A7, I would get =F$7 + G7.

    I was thinking this should be a two step process:
    1. "=RC[1]+RC[2]"
    2. somehow make only the second absolute reference.

    I know I can convert the whole formula to absolutes with a macro, but I'm not sure if I can iterate over the whole formula e.g. just change the first and third references to absolute, but leave the second reference as relative.

    I was looking at the following for inspiration (which doesn't work in this form), but gave me a general idea:
    Sub Macro19()
    '
    ' Macro19 Macro
    '
    Dim RdoRange As Range
    Dim i As Integer
    Dim Reply As String

    'Relative row/Absolute column

    For i = 1 To RdoRange.Areas.Count
    RdoRange.Areas(i).Formula = _
    Application.ConvertFormula _
    (Formula:=RdoRange.Areas(i).Formula, _
    FromReferenceStyle:=xlA1, _
    ToReferenceStyle:=xlA1, ToAbsolute:=xlRelRowAbsColumn)
    Next i


    'Clear memory
    Set RdoRange = Nothing
    End Sub

    Thanks for any help, it would be greatly appreciated!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro to change only part of a formula to absolute

    Quote Originally Posted by Chaba View Post
    For example, if I started in A6, I want the formula to say something like =F$6 + G6 and when I pull it down and if I started in A7, I would get =F$7 + G7.
    One possibility is to concatenate the absolute value within the formula string.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-29-2014
    Location
    Baltimore
    MS-Off Ver
    2010
    Posts
    19

    Re: Macro to change only part of a formula to absolute

    That seems to work fairly well. I think I understand the function you provided and have been manipulating it to fit my actual formula. One final question though, can the row be changed to two higher? So if the active cell is F6, how would I get it to give me F$2? Something like:

    Please Login or Register  to view this content.
    (This doesn't work of course). Thanks!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro to change only part of a formula to absolute

    Try this

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-29-2014
    Location
    Baltimore
    MS-Off Ver
    2010
    Posts
    19

    Re: Macro to change only part of a formula to absolute

    Yeah I was just playing around with it and found that. Before I was using brackets, which it didn't like :p Thanks again!

+ 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] Absolute reference for part of formula
    By aaaaaaiden in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-14-2014, 09:05 AM
  2. Formula with absolute values that change?
    By Jules1816 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-11-2013, 08:38 AM
  3. Replies: 3
    Last Post: 01-17-2010, 08:26 AM
  4. change absolute reference in a formula
    By mingali in forum Excel General
    Replies: 6
    Last Post: 09-13-2009, 11:03 PM
  5. Replies: 1
    Last Post: 01-07-2005, 10:06 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