+ Reply to Thread
Results 1 to 13 of 13

Replace a formula with it's value - do I need to macro?

  1. #1
    Registered User
    Join Date
    10-10-2008
    Location
    Moscow
    Posts
    6

    Replace a formula with it's value - do I need to macro?

    Thank god this forum exists, ok ... here goes ...

    I have a spreadsheet with 2 columns (let's pretend), the first column uses Data Validation for a dropdown list. The second column contains a formula that references the 1st column and uses lookup:

    =IF(A35<>0;LOOKUP(A35;NewCons;NewGroups))

    So as soon as a value is selected in column A, column B changes to display a value.

    Rather than just displaying this value, I would like the cell in column B to be completely replaced by this value, so goodbye to the formula.

    Is there a way that I can do this? Will I need to go and study how to use macros?

    Thanks in advance
    Last edited by VBA Noob; 11-14-2008 at 09:36 AM.

  2. #2
    Registered User
    Join Date
    10-08-2008
    Location
    Göteborg, Sweden
    Posts
    16
    Before I try to answer let me just ask you: Why do you not want the formula?

  3. #3
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    (let's pretend)
    I'm a cowboy



    Basically, yes, it's much easier to do this with a macro than without, but it looks like a pretty easy operation... try this:

    Right click on the sheet tab - click view code - paste inside then close that window
    Please Login or Register  to view this content.
    Now type in A35...

    HTH
    Last edited by Cheeky Charlie; 10-10-2008 at 05:05 AM. Reason: oops! forgot the whole point

  4. #4
    Registered User
    Join Date
    10-10-2008
    Location
    Moscow
    Posts
    6
    Quote Originally Posted by Winterbay View Post
    Before I try to answer let me just ask you: Why do you not want the formula?
    Because as time goes on the data that is being referred to in the LOOKUP will change, but we don't want these cells to automatically update when that happens -- we want to keep these cells "historic"...

  5. #5
    Registered User
    Join Date
    10-10-2008
    Location
    Moscow
    Posts
    6
    wow this is impressive, though I don't entirely understand it ---

    now would it be simple to change it so that it effects all cells in column A/B, and not just row 35?

    Quote Originally Posted by Cheeky Charlie View Post
    I'm a cowboy



    Basically, yes, it's much easier to do this with a macro than without, but it looks like a pretty easy operation... try this:

    Right click on the sheet tab - click view code - paste inside then close that window
    Please Login or Register  to view this content.
    Now type in A35...

    HTH

  6. #6
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    Thanks,

    Change this:
    Please Login or Register  to view this content.
    To this:
    Please Login or Register  to view this content.
    HTH

  7. #7
    Registered User
    Join Date
    10-08-2008
    Location
    Göteborg, Sweden
    Posts
    16
    Ah right, good reason. Also yes a macro is probably the easiest solution, but you already have one now so

  8. #8
    Registered User
    Join Date
    10-10-2008
    Location
    Moscow
    Posts
    6
    For some reason this doesn't seem to be working.
    I've tried to work out what the code is doing,
    is it just checking the cell (when it's targeted), and if it's in column 1 (column A?) AND if target(1,2) (which I assume means the cell to the right) is empty, it runs the lookup function
    but
    What does this Range part do?
    Couldn't it be simplified so if any cell in this column is targeted, it runs the lookup function and sets the value of target(1,2) to the result of the lookup?

    thanks in advance for excusing my ignorance

  9. #9
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    Hehe! Sorry, that was idle of me, I didn't check my reply thoroughly. Try this:

    Please Login or Register  to view this content.
    (Yes, you understand the code, and so you should be able to understand what I forgot to do!)

    HTH

  10. #10
    Registered User
    Join Date
    10-10-2008
    Location
    Moscow
    Posts
    6
    Sorry guys I'm still struggling with this

    As a test, I created a new workbook.
    I copied this code you've supplied and pasted it into sheet1's code.
    Then on sheet2, in columns A and B I put values a,b,c,d and e ... and 1, 2, 3, 4 and 5.
    Selected each set and gave them names, newcons and newgroups.
    I assume this is all that's required?

    Then I went to sheet 1 and entered a value in cell A1
    As soon as I clicked away I got a macro error.

    Please help

  11. #11
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    The code didn't allow for the lookup ranges being on a different sheet, you will need to change the sheet name in the code below

    Please Login or Register  to view this content.
    HTH

  12. #12
    Registered User
    Join Date
    10-10-2008
    Location
    Moscow
    Posts
    6
    AHHH finally got it working the way I wanted

    Thankyou thankyou thankyou so much!!

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Replace a formula with it's value - do I need to macro?

    Jeferson11,

    Welcome to the Forum.

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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. Find & Replace Macro
    By Huly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2008, 07:47 PM
  2. Pasting a Formula in a Macro
    By Alexander_Read in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2008, 10:49 AM
  3. Formula or a macro to return the first three digits of a number
    By westonkw in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2008, 03:54 PM
  4. Replies: 7
    Last Post: 03-03-2008, 11:48 AM
  5. Reset formula in macro
    By NMullis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2008, 06:10 PM

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