+ Reply to Thread
Results 1 to 4 of 4

if or statement

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    if or statement

    I am trying to have a time cell filled based of off of what is in another cell. I came up with a formula that works until I put more than two conditions in it stops working. Here is my formula:

    =IF(OR(G32=”AV”,G32=”BT”,G32=”DR”,G32=”OT”,G32=”NS”,G32=”RL”,G32=”TA”,G32=”ME”,G32=”VI”),NOW(),””)

    My original formula was:

    =IF(G32="RL",NOW(),"")

    Cell G32 will have one of the listed results typed in and I want this cell to put the time of the entry in as it is being entered and the time will be a static after entry.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,270

    Re: if or statement

    to Fix time stamp

    Only by using VBA event code in the worksheet.
    
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    'when entering data in a cell in Col A
    On Error GoTo enditall
    Application.EnableEvents = False
    If Target.Cells.Column = 1 Then
    n = Target.Row
    If Excel.Range("A" & n).Value <> "" Then
    Excel.Range("B" & n).Value = Now
    End If
    End If
    enditall:
    Application.EnableEvents = True
    End Sub
    Right-click on the sheet tab and "View Code".

    Copy/paste the above into that sheet module.

    When you enter data in any cell in column A, a static date/time stamp goes into
    column B on same row.

    and ...

    =IF(OR(G32="AV",G32="BT",G32="DR",G32="OT",G32="NS",G32="RL",G32="TA",G32="ME",G32="VI"),NOW(),"")

    you have italicised quotes ” ?????

  3. #3
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    Re: if or statement

    Thank you for that information. I entered it and I works well for my column "A" to put date into my column "f". I also tried to put it in as:


    but I get an error. I need the first for column "A" to date column "F" then for column "L" to date column "G". I thought I could just copy it again and change the variables but I get the "compile error: ambiguous name detected: Worksheet_change" message. This is what I put in:

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    'when entering data in a cell in Col L
    On Error GoTo enditall
    Application.EnableEvents = False
    If Target.Cells.Column = 1 Then
    n = Target.Row
    If Excel.Range("L" & n).Value <> "" Then
    Excel.Range("G" & n).Value = Now
    End If
    End If
    Thank you for any explanation of what I have done wrong.

  4. #4
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: if or statement

    Hi COURTTROOPER ,

    I do not know how to make the formula to be a static after entry.

    but I have a bit improvement on the formula, as I saw whole formula is refer to same cell.
    you may try to use { and }

    Formula: copy to clipboard
    =IF(OR(G32={"AV","BT","DR","OT","NS","RL","TA","ME","VI"}),NOW(),"")
    Hope you can learn every time you visit here.

    If you still confuse on how it work, kindly ask or go to
    i) Formula - Formula (Ribbon) > Formula Auditing (Section) > Evaluate Formula > Evaluate; or
    ii) VBA/Code - Click F8 to see how it work step by step.

    It it take care of your question, Please:
    Mark tread as [Solved] [Thread Tools->Mark thread as Solved]
    ;and
    Click *Add Reputation to thank anyone solved your question.

+ 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: 2
    Last Post: 07-09-2015, 04:25 PM
  2. [SOLVED] If statement to select data - nested statement - assistance
    By petitesouris in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-29-2015, 09:55 PM
  3. compile error expected line number statement end statement
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2014, 10:12 AM
  4. VBA Compile Error : line number or label or statement or end of statement
    By excellearner121 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2013, 06:41 PM
  5. Replies: 4
    Last Post: 06-01-2012, 10:05 AM
  6. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  7. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08:55 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