VBA with condition

Abhishekghorpade

Board Regular
Joined
Oct 3, 2018
Messages
78
Hi,

Could you please help with VBA code for below condition

If the date in Column “I” is between 01/01/2017 to 12/31/2017 and Column “H” is >=0.50 Column A should display as A else D
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You can do it with an equation:
=IF(AND(YEAR(I1)=2017,H1>=0.5),"A","D")
 
Last edited:
Upvote 0
If you want to do it using VBA then this will do it for you:
Code:
Sub test()
lastrow = Cells(Rows.Count, "I").End(xlUp).Row
inarr = Range(Cells(1, 8), Cells(lastrow, 9))
For i = 1 To lastrow
 Yr = Year(inarr(i, 2))
 If Yr = "2017" And inarr(i, 1) >= 0.5 Then
  Cells(i, 1) = "A"
 Else
  Cells(i, 1) = "D"
 End If
Next i
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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