1

I have a column A, that contains either one of the following values:

DATEnone
nonenone
noneTIME
DATETIME

I want to write a function that basically does this:

if A1 is "DATEnone" or A1 is DATETIME:
 A1 = "D"
elif A1 is "noneTIME":
 A1 = "T"
else:
 A1 = "S"

how can I do that in an excel cell function?

2
  • A function or a sub to replace the contents? Commented Feb 19, 2014 at 9:32
  • tried IF( condition1, value_if_true1, IF( condition2, value_if_true2, IF( condition3, value_if_true3, value_if_false3) )) but that breaks down when I TIME and DATE is in the string such as in DATETIME Commented Feb 19, 2014 at 9:33

1 Answer 1

3

Copy-Paste this code in a new module and hit F5 to run the macro.

Sub Main()
Application.ScreenUpdating = False
    Dim c As Range
    For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
        If StrComp("DATEnone", c, 1) = 0 Or StrComp("DATETIME", c, 1) = 0 Then
            c = "D"
        ElseIf StrComp("noneTime", c, 1) = 0 Then
            c = "T"
        Else
            c = "S"
        End If
    Next c
Application.ScreenUpdating = True
End Sub

This code iterates over column A and replaces the contents based on the conditions you specified.


And if you wanted just a function then stick this formula

=IF(OR(A1="DATEnone", A1="DATETIME"),"D", IF(A1="noneTime","T","S"))

in cell B1 and drag it down the B column

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.