IF + Manual

%3CLINGO-SUB%20id%3D%22lingo-sub-2669236%22%20slang%3D%22en-US%22%3EIF%20%2B%20Manual%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2669236%22%20slang%3D%22en-US%22%3E%3CP%3EHello!%20I%20would%20need%20a%20function%20to%20do%20the%20following%20(for%20example)%3A%3C%2FP%3E%3CP%3E%3DIF(A1%3D1%3B%22X%22%3B%22_allow%20manual%20text_%22)%3C%2FP%3E%3CP%3EIn%20words%3A%20I%20would%20like%20a%20cell%20to%20be%20filled%20automatically%20if%20some%20conditions%20are%20met%2C%20but%20manually%20if%20they%20are%20not%2C%20but%20without%20losing%20the%20formula%20in%20the%20cell%20to%20be%20filled.%3C%2FP%3E%3CP%3EIs%20it%20possible%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2669236%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2669311%22%20slang%3D%22en-US%22%3ERe%3A%20IF%20%2B%20Manual%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2669311%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1133295%22%20target%3D%22_blank%22%3E%40Lucassis%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20literally%20possible.%20Once%20you%20enter%20something%20else%20%22manually%22%20you've%20obliterated%20what%20was%20there%20before.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20you%20could%20do%20your%20manual%20entry%20in%20a%20designated%20cell%20in%20the%20same%20row%2C%20off%20to%20the%20side.%3C%2FP%3E%3CP%3EAssume%20your%20%22X%22%20--predetermined%20%22normal%22%20condition%20text--is%20in%20cell%20X1%3C%2FP%3E%3CP%3ESet%20aside%20column%20%22Y%22%20(but%20every%20row%20running%20down%20the%20sheet)%20for%20your%20manual%20entry%3C%2FP%3E%3CP%3EThe%20formula%20could%20then%20read%3C%2FP%3E%3CP%3E%3CSPAN%3E%3DIF(A1%3D1%3B%24X%241%3BY1)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAnother%20solution%2C%20depending%20on%20how%20many%20%22manual%22%20entries%20are%20expected%2C%20how%20fluid%20you%20want%20those%20to%20be...if%2C%20in%20other%20words%2C%20your%20normal%20expectation%20is%20answer%20A%2C%20but%20you%20also%20will%20allow%20B%2C%20C%2C%20D%2C%20E%2C%20F%2C%20G%2C%20H%20(etc.%2C%20but%20finite)%20is%20to%20use%20%3CSTRONG%3EData%20Validation%3C%2FSTRONG%3E%20with%20A%20as%20the%26nbsp%3Bdefault%20value.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIn%20short%2C%20I%20can%20envision%20several%20ways%20to%26nbsp%3Bapproach%20this%2C%20but%20would%20need%20to%20find%20out%20from%20you%20a%20bit%20more%20the%20%22big%20picture%22%20of%20what%20you're%20trying%20to%20do.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2669333%22%20slang%3D%22en-US%22%3ERe%3A%20IF%20%2B%20Manual%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2669333%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1133295%22%20target%3D%22_blank%22%3E%40Lucassis%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20cannot%20do%20that%20with%20a%20formula%3B%20it%20would%20require%20VBA.%20If%20that%20is%20OK%3A%20let's%20say%20you%20want%20to%20apply%20this%20to%20cells%20B1%3AB10%20-%20if%20the%20corresponding%20cell%20in%20A1%3AA10%20equals%201%2C%20enter%20%22X%22%2C%20otherwise%20let%20the%20user%20enter%20data.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERight-click%20the%20sheet%20tab.%3C%2FP%3E%0A%3CP%3ESelect%20'View%20Code'%20from%20the%20context%20menu.%3C%2FP%3E%0A%3CP%3EEnter%20the%20following%20code%20into%20the%20worksheet%20module%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0A%20%20%20%20Dim%20rng%20As%20Range%0A%20%20%20%20If%20Not%20Intersect(Range(%22A1%3AA10%22)%2C%20Target)%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20Application.EnableEvents%20%3D%20False%0A%20%20%20%20%20%20%20%20For%20Each%20rng%20In%20Intersect(Range(%22A1%3AA10%22)%2C%20Target)%0A%20%20%20%20%20%20%20%20%20%20%20%20If%20rng.Value%20%3D%201%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rng.Offset(0%2C%201).Value%20%3D%20%22X%22%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20Next%20rng%0A%20%20%20%20%20%20%20%20Application.EnableEvents%20%3D%20True%0A%20%20%20%20End%20If%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESwitch%20back%20to%20Excel.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESelect%20B1%3AB10.%3C%2FP%3E%0A%3CP%3EOn%20the%20Data%20tab%20of%20the%20ribbon%2C%20click%20Data%20Validation.%3C%2FP%3E%0A%3CP%3ESelect%20Custom%20from%20the%20Allow%20drop-down.%3C%2FP%3E%0A%3CP%3EEnter%20the%20formula%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DOR(A1%26lt%3B%26gt%3B1%2CB1%3D%22X%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EActivate%20the%20Error%20Alert%20tab.%3C%2FP%3E%0A%3CP%3EEnter%20an%20appropriate%20error%20message%20to%20be%20displayed%20if%20the%20user%20tries%20to%20enter%20something%20else%20than%20%22X%22%20if%20column%20A%20contains%201.%3C%2FP%3E%0A%3CP%3EClick%20OK.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESave%20the%20workbook%20as%20a%20macro-enabled%20workbook%20(.xlsm).%3C%2FP%3E%0A%3CP%3EMakes%20sure%20that%20you%20allow%20macros%20when%20you%20open%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hello! I would need a function to do the following (for example):

=IF(A1=1;"X";"_allow manual text_")

In words: I would like a cell to be filled automatically if some conditions are met, but manually if they are not, but without losing the formula in the cell to be filled.

Is it possible? 

2 Replies

@Lucassis 

 

Not literally possible. Once you enter something else "manually" you've obliterated what was there before.

 

However, you could do your manual entry in a designated cell in the same row, off to the side.

Assume your "X" --predetermined "normal" condition text--is in cell X1

Set aside column "Y" (but every row running down the sheet) for your manual entry

The formula could then read

=IF(A1=1;$X$1;Y1)

 

Another solution, depending on how many "manual" entries are expected, how fluid you want those to be...if, in other words, your normal expectation is answer A, but you also will allow B, C, D, E, F, G, H (etc., but finite) is to use Data Validation with A as the default value.

 

In short, I can envision several ways to approach this, but would need to find out from you a bit more the "big picture" of what you're trying to do.

 

@Lucassis 

You cannot do that with a formula; it would require VBA. If that is OK: let's say you want to apply this to cells B1:B10 - if the corresponding cell in A1:A10 equals 1, enter "X", otherwise let the user enter data.

 

Right-click the sheet tab.

Select 'View Code' from the context menu.

Enter the following code into the worksheet module:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    If Not Intersect(Range("A1:A10"), Target) Is Nothing Then
        Application.EnableEvents = False
        For Each rng In Intersect(Range("A1:A10"), Target)
            If rng.Value = 1 Then
                rng.Offset(0, 1).Value = "X"
            End If
        Next rng
        Application.EnableEvents = True
    End If
End Sub

Switch back to Excel.

 

Select B1:B10.

On the Data tab of the ribbon, click Data Validation.

Select Custom from the Allow drop-down.

Enter the formula

=OR(A1<>1,B1="X")

Activate the Error Alert tab.

Enter an appropriate error message to be displayed if the user tries to enter something else than "X" if column A contains 1.

Click OK.

 

Save the workbook as a macro-enabled workbook (.xlsm).

Makes sure that you allow macros when you open it.