+ Reply to Thread
Results 1 to 12 of 12

How to: free text cell, that can also assume a value depending on other cell?

Hybrid View

  1. #1
    Registered User
    Join Date
    12-08-2024
    Location
    Sweden
    MS-Off Ver
    Version 2410
    Posts
    5

    Question How to: free text cell, that can also assume a value depending on other cell?

    Hello!

    Help would be very, very appreciated!

    What I would like to do is to have a cell where:
    A) you can write free text
    and
    B) if a specific other cell with a drop-down list has a value, my cell will pick up a value depending on that.

    I find myself in a dilemma, because I can make the cell do B), but then I can't write free text there anymore (because the code is there).

    The scenario, if that helps, is that I
    A) want to be able to write free text a price in a cell,
    but also,
    B) when I choose common items from a drop-down list, the corresponding price will automatically appear in the price cell.

    My best idea so far (which I don't know is possible) is to program something that's not in the cell. For example instruct the sender of information instead of the receiver. If I could make the drop-down "send" value to my cell when it has one, and just let it be when there is no value to be sent, that would be awesome. But so far in my short experience with Excel I haven't seen anything like that.

    Thank you so much in advance!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,034

    Re: How to: free text cell, that can also assume a value depending on other cell?

    Short story: no, you can't do that. A cell can have a value or a formula, but not both.

    If you overwrite a formula with text, you lose the formula . . . for good, unless you replace it.

    You would need VBA.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    12-08-2024
    Location
    Sweden
    MS-Off Ver
    Version 2410
    Posts
    5

    Re: How to: free text cell, that can also assume a value depending on other cell?

    Thank you for answering!

    Sad, though.

    VBA, is that something doable? Do you have any recommendation of what in VBA it would be good to look into in order to learn what I need?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,034

    Re: How to: free text cell, that can also assume a value depending on other cell?

    VBA is not a five minute learn. But what you need is not difficult or complicated.

    You would need a Worksheet Change Event handler monitoring the cell(s) withe Data Validation drop down. When you select a value, you execute the formula (in the code) and put the returned value in the target cell.

    Post a sample workbook and we can give you the code.

  5. #5
    Registered User
    Join Date
    12-08-2024
    Location
    Sweden
    MS-Off Ver
    Version 2410
    Posts
    5

    Re: How to: free text cell, that can also assume a value depending on other cell?

    I kind of guessed that, looking into it a little it seems like a bit of a new (but very exciting!) world to me.

    Thank you for the explaination!

    That would be so very kind. I try to post a sample workbook.
    Attached Files Attached Files

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,034

    Re: How to: free text cell, that can also assume a value depending on other cell?

    In the workbook, you mention cell C9. However, that is not affected by the drop down selection. I think you mean cell G9, and that is what the code updates.

    Right click on the Calculations tab
    Select "View Code"
    In the Main code pane, paste the following code:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    ' Define and set the "range of interest" = cell E9
    Dim rInterest As Range
    Set rInterest = Me.Range("E9")
    
    ' Check if the Target cell is the range of interest
    If Intersect(Target, rInterest) Is Nothing Then Exit Sub
    ' Check if multiple cells have changed (say, if clearing several cells)
    If Target.Cells.CountLarge > 1 Then Exit Sub
    
    Application.EnableEvents = False    ' Stop Event handling
    On Error Resume Next                ' Continue if any error(s)
    
    If Target.Value = "" Then
        ' Clear the cell if the Target is empty
        Target.Offset(, 2).Value = ""
    Else
        ' Drop the formula into the cell
        With Target.Offset(, 2)
            .Formula = _
                "=IFERROR(VLOOKUP(" & Target.Address & ",Data!B77:D87,3,FALSE),"""")"
            .Value = .Value
        End With ' Target.Offset(, 2)
    End If ' Target.Value = ""
    
    On Error GoTo 0                 ' Clear Error handling
    Application.EnableEvents = True ' Resume Event handling
    
    End Sub
    Please note that you will need to save your workbook as macro enabled (.xlsm or .xlsb). And you will need to enable macros when you open the workbook.

    Please see the attached updated sample workbook.
    Attached Files Attached Files

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,034

    Re: How to: free text cell, that can also assume a value depending on other cell?

    Note: I would suggest that you use Nested IF statements rather than IFS. The IFS function is very inefficient as it has to evaluate every criterion and every result before selecting the first matching result.

  8. #8
    Registered User
    Join Date
    12-08-2024
    Location
    Sweden
    MS-Off Ver
    Version 2410
    Posts
    5

    Re: How to: free text cell, that can also assume a value depending on other cell?

    Thank you so so much! It works perfectly!
    Actually I meant C9, I just moved my old code out of the way since I figured it's probably useless xD But it was easy to change, I just exchanged (,2) to (,-2) in a few places

    I thought I would be able to do several of these - I'm making a form that repeats itself 5 times down the sheet. The goal is to have C9 affected by E9, but also C40 by E40, C71 by E71, C102 by E102 and C133 by E133. I tried a bunch of things but I can't make it work. Any advice?

    Also, thank you for the advice regarding using VBA and regarding IFS! I felt like I could keep organized easier with an IFS formula than with an IF, and didn't realize the disadvantages.
    Last edited by EmmaLearns; 12-12-2024 at 11:18 AM. Reason: typo

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,034

    Re: How to: free text cell, that can also assume a value depending on other cell?

    Try:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    ' The goal is to have C9 affected by E9,
    ' but also C40 by E40, C71 by E71,
    ' C102 by E102 and C133 by E133.
    
    ' Define and set the "range of interest" = cell E9
    Dim rInterest As Range
    Set rInterest = Me.Range("E9, E40, E71, E102, E133")
    You shouldn't need to change anything else.

  10. #10
    Registered User
    Join Date
    12-08-2024
    Location
    Sweden
    MS-Off Ver
    Version 2410
    Posts
    5

    Re: How to: free text cell, that can also assume a value depending on other cell?

    Oooh it works just as I want it to! Thank you so much!!

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,034

    Re: How to: free text cell, that can also assume a value depending on other cell?

    You're welcome.



    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon (Next to Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,034

    Re: How to: free text cell, that can also assume a value depending on other cell?

    Thanks for the rep.

+ 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: 3
    Last Post: 01-20-2022, 10:21 AM
  2. Drop-Down List OR Free Text Dependent On Another Cell's Value
    By STBTC in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-02-2022, 09:33 AM
  3. Formula to add free text to a cell on a continuoual basis
    By sekhar_gs in forum Excel General
    Replies: 3
    Last Post: 10-02-2017, 08:52 AM
  4. [SOLVED] Find Multiple keywords from free text cell
    By amitmodi_mrt in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-31-2017, 02:58 AM
  5. how to make a particular cell assume the name of the worksheet
    By kelsnjoku in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-05-2014, 05:17 AM
  6. [SOLVED] Looking for formula to extract state names from free text cell... HELP!
    By howardulson in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-22-2014, 04:46 PM
  7. Stopping free text entry in validation cell
    By smf in forum Excel General
    Replies: 2
    Last Post: 12-15-2005, 03:50 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