Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I have the following IF condition in some cell:

=IF(A1>A2, "value is <C5>", "value is <D5>")

where <C5> and <D5> should be the values of cells C5 and D5.

I know it is a simple question but searching was not successful. I don't really know how to phrase this.

share|improve this question
    
How about just =IF(A1>A2, C5, D5) –  Vidar S. Ramdal Apr 28 at 14:22
    
@VidarS.Ramdal text is mandatory. cannot be omitted. I need something like: "value is %s, D5". don't know what the syntax is. –  idanshmu Apr 28 at 14:24
    
Ah, of course. See answer below (in a second). –  Vidar S. Ramdal Apr 28 at 14:25

1 Answer 1

up vote 3 down vote accepted

You can use the string concatenation operator, &:

=IF(A1>A2, "value is " & C5, "value is " & D5)

This is equal to, but less verbose than:

=IF(A1>A2, CONCAT("value is ", C5), CONCAT("value is ", D5))

As to your follow-up comment, you can concatenate several strings and values:

=IF(A1>A2, "value is " & C5 & " right now, but could be " & D5, "value is " & D5 & " at the moment, but could be " & C5)

Also see Combining stuff in Google Spreadsheet

share|improve this answer
    
lovely. 10x a lot. –  idanshmu Apr 28 at 14:32
    
BDW, what if I have multiple cell values that I want to insert in different places in the text? –  idanshmu Apr 28 at 14:35
    
See revised answer. –  Vidar S. Ramdal Apr 28 at 14:40
    
oh I see. great. thanks for your time –  idanshmu Apr 28 at 14:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.