+ Reply to Thread
Results 1 to 27 of 27

converting Formula into absolute value

  1. #1
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    converting Formula into absolute value

    I'm enclosing a sample workbook. In my sheet Cells K4:L6 are linked with Cells F4:G6.

    I want that if cell J2=2, then the values of K4:L6 becomes absolute values (not linked with F4:G6), but if Cell J2=1, then again K4:L6 are linked with F4:G6.



    This post is also posted at OZGRID.com. The link to this post is as follows;

    [URL="https://www.ozgrid.com/forum/index.php?thread/1227377-vba-code-for-converting-formula-to-value/&postID=1234499#post1234499"]
    Last edited by leo73pk; 04-30-2020 at 08:55 AM. Reason: Solved
    Best Regards,
    Hamza


    It is the greatest of all mistakes to do nothing because you can only do little - do what you can.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,723

    Re: converting Formula into absolute value

    It is not possible to do what you want. A cell can contain either a value or a formula, but not both, so you cannot make it switch between being linked to another cell and containing a value in the way you describe. It may be possible using VBA - shall I move the thread for you?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    sure you can.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,723

    Re: converting Formula into absolute value

    What - move the thread? Or are you saying that I am wrong? Please be clear.

  5. #5
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    Move the thread for VBA solution.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,723

    Re: converting Formula into absolute value

    Please ...

    OK - I'm moving it now.

  7. #7
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    Ali Thanks for moving the thread to the appropriate forum.

  8. #8
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: converting Formula into absolute value

    And what if J2 <> 1 or <> 2

  9. #9
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    J2 must be either 1 or 2

  10. #10
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: converting Formula into absolute value

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    After saving the workbook as macro enabled workbook I copied this vba code and save the file once I change the value of J2 from 1 to 2, it gives an error message;

    "compile error: Expected endsub"

    Kindly advise

  12. #12
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: converting Formula into absolute value

    Then you will not have applied it properly.

    You ask for a VBA solution and then I assume that you also have some knowledge of it.

  13. #13
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    My apologies, I missed End Sub.
    What if I have to apply it for multiple ranges on the same sheet.

  14. #14
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    Vraag, thanks for your prompt reply. The proposed VBA code works for a single Cell Range K4:L6 but when I apply it for multiple ranges by adding following changes

    With Range("K4:L6", "K10:L12")"

    it works but when I change the value of J2 to 1, in Cells K7:L8 link established with F7:G8.

    Kindly advise

  15. #15
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: converting Formula into absolute value

    You run that risk if you are not completely in the question. I have given you how to tackle it with code. So you may first try something yourself.

  16. #16
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    I have tried Sir, That's why i'm asking that once I made certain change to the code you proposed it serves the purpose for multiple ranges but as I mentioned above it gives outcome like this

    "The proposed VBA code works for a single Cell Range K4:L6 but when I apply it for multiple ranges by adding following changes

    With Range("K4:L6", "K10:L12")"

    it works but when I change the value of J2 to 1, in Cells K7:L8 link established with F7:G8. I only want that this vba code applies to the multiple ranges I defined.

    Kindly advise

  17. #17
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    I have used this VBA code

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) = "J2" Then
    With Range("K4:L6,K10:L12,K16:L18")
    If Target.Value = 2 Then .Value = .Value Else .Formula2R1C1 = "=RC[-5]"
    End With
    End If
    End Sub

    Its working for K4:L6 and K16:L18 cell ranges. but when I turn the value of cell J2 to 2 it gives undesired results for K10:L12 (sample workbook is enclosed)

    Please advise how to get this resolved.

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,723

    Re: converting Formula into absolute value

    Administrative Note:

    We would very much like to continue to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  19. #19
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    I have used this VBA code


    Please Login or Register  to view this content.
    Its working for K4:L6 and K16:L18 cell ranges. but when I turn the value of cell J2 to 2 it gives undesired results for K10:L12 (sample workbook is enclosed)

    Please advise how to get this resolved.
    Last edited by leo73pk; 04-27-2020 at 04:32 PM. Reason: to attach sample file

  20. #20
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    In the enclosed workbook, the below VBA code works as per the requirement i.e. when Cell J2=2, Cell K4:L6 formula becomes absolute values and when Cell J2=1 again the Cell K4:L6 formula restored (its link with Cells F4:G6).

    Please Login or Register  to view this content.

    Now i want to modify the above VBA code in such manner that it works the same ways for other cell ranges K10:L12 and K16:L18 or any other cell ranges which i opt to definer later. Sample workbook is enclosed for reference.

  21. #21
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: converting Formula into absolute value

    How about this.

    Formula2 uses A1-style.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  22. #22
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    Quote Originally Posted by bakerman2 View Post
    How about this.

    Formula2 uses A1-style.

    Please Login or Register  to view this content.
    The change you proposed is giving the same result as the existing vba code.

    I want to amend this vba code that it works in a similar manner as it is currently working for cell range K6:L6 based on Cell J2 value. Therefore, I'm looking forward to have an amended VBA code so that it work for K10:L12 and K16:L18 or any other cell ranges which I opt to define later. Sample workbook is enclosed for reference.
    Last edited by leo73pk; 04-28-2020 at 09:07 AM. Reason: repharasing

  23. #23
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: converting Formula into absolute value

    Temporary solution.

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    Dear Bakerman2,

    You have mentioned a Temporary Solution before the VBA code. what does that mean?. However, your VBA code serves the purpose as per the structure of my enclosed sample workbook. I'll appreciate if you suggest the changes in VBA code, if I the same procedure to be performed on cells which are not at RC(-5) position. i.e. F21:G21 are linked with B4:C4 and N23 linked with B6. how to include that in VBA Code.

  25. #25
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: converting Formula into absolute value

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)

  26. #26
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    This post is also posted at OZGRID.com. The link to this post is as follows;


    https://www.ozgrid.com/forum/index.p...99#post1234499
    Last edited by Pepe Le Mokko; 04-29-2020 at 08:14 AM. Reason: Corrected link No need for URL tags

  27. #27
    Forum Contributor leo73pk's Avatar
    Join Date
    09-28-2006
    Location
    UAE
    MS-Off Ver
    2016, Microsoft 365
    Posts
    294

    Re: converting Formula into absolute value

    Thanks Bakerman2,

    Your proposed VBA Code gives the desired result. Thanks a lot for your time to help me.

+ 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. Replies: 8
    Last Post: 05-08-2017, 08:51 PM
  2. Replies: 0
    Last Post: 04-08-2013, 05:08 AM
  3. [SOLVED] Converting Time to an Absolute Number
    By ikey in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-11-2012, 04:31 AM
  4. Replies: 2
    Last Post: 06-09-2012, 07:31 AM
  5. Replies: 3
    Last Post: 04-05-2011, 09:32 AM
  6. Converting to Absolute Cell References - en bloc
    By Basher Bates in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-11-2006, 05:10 PM
  7. Converting to absolute reference
    By T De Villiers in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-26-2006, 10:25 AM

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