Results 1 to 4 of 4

Thread: If Elseif else statement
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Aug 2019
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default If Elseif else statement

    How to write a VBA code to get the below output.


    If Column A = Internal, Then column F = ok and


    If Column C = Long or Short Then column F = ok


    and if Column A is anything else, then it should check if Column C = Long or Short if yes then column F = ok else column F = check.


    Thank you in Advance

  2. #2
    Board Regular kweaver's Avatar
    Join Date
    May 2018
    Location
    La Jolla, CA
    Posts
    629
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: If Elseif else statement

    Are you comparing Column A's ROWS with the word "Internal" and C's ROWS with the words "Long" or "Short" ?
    Last edited by kweaver; Sep 10th, 2019 at 01:23 AM.

  3. #3
    Board Regular kweaver's Avatar
    Join Date
    May 2018
    Location
    La Jolla, CA
    Posts
    629
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: If Elseif else statement

    If so (per my previous post), then try:

    Code:
    Sub CheckCells()
    Dim lr As Long, i As Integer
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To lr
     If Cells(i, 1) = "Internal" And (Cells(i, 3) = "Long" Or Cells(i, 3) = "Short") Then
     Cells(i, 6) = "OK"
     Else
     Cells(i, 6) = "Check"
     End If
    Next i
    End Sub
    You don't actually need VBA for this. You can fill this down in the F column:

    Code:
    =IF(AND("Internal"=A1,OR("Long"=C1,"Short"=C1)),"OK","Check")

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,190
    Post Thanks / Like
    Mentioned
    470 Post(s)
    Tagged
    47 Thread(s)

    Default Re: If Elseif else statement

    My take on this.
    Via formula
    =IF(A2="Internal","Ok",IF(OR(C2={"Long","short"}),"Ok","Check"))

    code
    Code:
    Sub vijaycs()
       With Range("F2:F" & Range("A" & Rows.Count).End(xlUp).Row)
          .Value = Evaluate(Replace("IF(" & .Offset(, -5).Address & "=""Internal"",""Ok"",IF((@c=""Long"")+(@c=""short""),""Ok"",""Check""))", "@c", .Offset(, -3).Address))
       End With
    End Sub
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •