+ Reply to Thread
Results 1 to 21 of 21

Changing Formula from absolute to Relative

  1. #1
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Changing Formula from absolute to Relative

    Hey,

    I have the code below which builds up an array of data and formulas the applies that array as a range. This is fine except is always comes out as absolute. I then got the code in at the bottom to find ranges of formulas and change them to relative after the data has rendered. This logic works fine on other worksheets but on this worksheet I get the error TypeMismatch when the line RdoRange.Areas(ranges).Formula = _
    Application.ConvertFormula _
    (Formula:=RdoRange.Areas(ranges).Formula, _
    FromReferenceStyle:=xlA1, _
    ToReferenceStyle:=xlA1, ToAbsolute:=xlRelative
    gets hit. Could anyone see what could be going wrong here?

    Please Login or Register  to view this content.
    Last edited by FishGuy; 09-17-2010 at 04:47 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing Formula from absolute to Relative

    Why using R1C1 notation in the first place ?
    You'd be better off with
    Please Login or Register  to view this content.
    The use of an array doesn't seem necessary.

    If using the formula conversion method (which I do not recommend, see above) I'd try
    Please Login or Register  to view this content.



  3. #3
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    Hi the reason we use the array is that is how we populate the xls from the database record set, apparently doing it by range is quicker than cell by cell so we first fill the array with the data then match the array to the range taking into account both data values and formulas in the same block.
    Looking at your fill down method I think that could work in new reports by doing the formulas seperate, unfortunately we already have numerous reports (some quite complex) using the existing model. Even worse it has only just come to light that this absolute issue is causing a problem.
    Last edited by teylyn; 09-15-2010 at 06:55 AM. Reason: removed quote

  4. #4
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    Please Login or Register  to view this content.
    I tried the above and on the line RdoRange.Areas(ranges).Formula = Application.ConvertFormula(rng.Formula, xlR1C1, xlA1, xlRelative)

    I still get the typr mismatch error.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing Formula from absolute to Relative

    You didn't copy my code properly.

  6. #6
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    Please Login or Register  to view this content.
    I am getting and application object not defined error with the above code on the line
    rng.Formula = Application.ConvertFormula(rng.Formula, xlR1C1, xlA1,
    Last edited by teylyn; 09-15-2010 at 06:55 AM. Reason: removed quote

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing Formula from absolute to Relative

    Please Login or Register  to view this content.
    This 3-liner is sufficient, remove the other codelines.

  8. #8
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    Possibly getting closer, that code runs without error and the lines do get hit but for somereason when the worksheet is displayed the forluma is still all absolute.

    e.g

    =IF($C$18<>0,$E$18/$C$18,0)

    and

    =[Analysis.xlsm]Detail!$R$65536) + SUMIF(Private!$W$8:$W$65536, $AB$20 & "/Onsite", Private!$R$8:$R$65536) + SUMIF(Public!$W$8:$W$65536, $AB$20 & "/Public", Public!$R$8:$R$65536) + SUMIF('3Party'!$W$8:$W$65536, $AB$20 & "/3Party", '3Party'!$R$8:$R$65536)
    Last edited by teylyn; 09-15-2010 at 06:55 AM. Reason: removed quote

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing Formula from absolute to Relative

    Please Login or Register  to view this content.

  10. #10
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Changing Formula from absolute to Relative

    FishGuy, please don't quote whole posts. Use the Quick Reply box instead of the Quote button to create a new post.

    Thanks

  11. #11
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    That code has chqanged the formula to relative but also changed the whole formula.
    for exapmle.
    The formula I put into the cells
    TempArray(Currenti, colSummaryInvoicedCore) = _
    "=SUMIF( Invoiced!" & Range(Cells(intSheetStartRow, colInvoicedKey1), Cells(65000, colInvoicedKey1)).Address & _
    ", " & Range(Cells(intRow, colSummaryKey1), Cells(intRow, colSummaryKey1)).Address & " & ""/Core""" & _
    ", Invoiced!" & Range(Cells(intSheetStartRow, colInvoicedSplitTotal), Cells(65000, colInvoicedSplitTotal)).Address & ")"

    The above formula used to come out like below
    =SUMIF( Invoiced!$U$8:$U$65000, $AB$17 & "/Core", Invoiced!$J$8:$J$65000)

    However it now appears like below
    =SUMIF( Invoiced!AA17:AA65009, AH26 & "/Core", Invoiced!P17:P65009)

    See how it no longer compares all the range from the 8th to th 65k but instead sums from the line it is on in the worksheet. I have no idea why it has changed AB17 to AH26 and Colums U to AA and J to P?
    Last edited by FishGuy; 09-16-2010 at 06:42 AM.

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing Formula from absolute to Relative

    Unless you post an example worksheet it's no use referring to variables we have no notion of what they contain or what value they have.

  13. #13
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    I would have to post the whole work book.

    Basically it is a summary sheet which is the first sheet of the workbook. The summary sheet lists employee names and various totals against their name in other columns and column U is a key column this also holds the employee name.

    On the summary sheet in the example above the column is called 'core sales' as it is used to display the value of sales with a sale type of core for this reason 'core' is appended to the key in the formula.

    the formula to fill this column looks up the data from a second workheet which displays all the detals of sales, this is the Invoiced sheet. The column we are summing up is column J which is the value of each sale. The invoiced sheet also has a key column which is made up of the name of the employee making the sale and the sale type this is Column AB. This allows us to match the key on the summary and sum up each persons sales from the Invoiced sheet where the sale type is of type for example 'Core'
    Last edited by FishGuy; 09-16-2010 at 06:53 AM.

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing Formula from absolute to Relative

    Interesting, but although most of the helpers in this forum can read minds, they lack the ability to read non-posted workbooks.

  15. #15
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    Ok I have uploaded a sample which should demonstrate whats going on.

    Basically it currently works perfectly, but if a user then does a sort on the data then then because it is all absolute the formula start displaying the wrong data which is why i need to change it.

    Please Login or Register  to view this content.
    Last edited by FishGuy; 09-16-2010 at 12:29 PM.

  16. #16
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing Formula from absolute to Relative

    =SUMIF( Invoiced!AA17:AA65009, AH26 & "/Core", Invoiced!P17:P65009)

    is the same as
    =SUMIF( Invoiced!$U$8:$U$65000, $AB$17 & "/Core", Invoiced!$J$8:$J$65000)

    with an offset(9,6)

  17. #17
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    Im not quite sure what you mean.

    When I use the code to change the formula to relative

    the workbook then renders like the workbook here instead of like the one above.
    Last edited by FishGuy; 09-16-2010 at 12:30 PM.

  18. #18
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    I changed
    Application.ConvertFormula cl.Formula, xlR1C1, xlA1, xlRelative
    to
    cl.Formula = Application.ConvertFormula(cl.Formula, xlA1, xlA1, xlRelative)
    and now the majority of values come out ok
    Except the ones in columns c,d,e on the summary sheet which now just say #VALUE

    Thats the ones
    Please Login or Register  to view this content.
    Last edited by FishGuy; 09-16-2010 at 10:02 AM.

  19. #19
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing Formula from absolute to Relative

    Did you overlook this one

  20. #20
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Changing Formula from absolute to Relative

    Wouldn't it be easier to form the addresses first, and then reuse them? Also, you can look at the addresses ...
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  21. #21
    Registered User
    Join Date
    09-14-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Changing Formula from absolute to Relative

    Yes, in the end rather than change the formula after the sheet had been updated I found I could specify relative when building the formula by using the .address method.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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