If Elseif else statement

vijaycs

New Member
Joined
Aug 17, 2019
Messages
8
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
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Are you comparing Column A's ROWS with the word "Internal" and C's ROWS with the words "Long" or "Short" ?
 
Last edited:
Upvote 0
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")
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top