Conditionally put data if condition met

Sachin Singh
Sachin Singh used Ask the Experts™
on
Conditionally put data if condition met
If Column H is greater than column I then Put in column K BUY
If column H is lower than column I then put in column K SELL
see the sample file
Book1.xlsb
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
Please try this...

Sub BuyORSellColumnK()
Dim ws As Worksheet
Dim lr As Long

Application.ScreenUpdating = False
Set ws = Sheets("Sheet2")
lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
With Range("K2:K" & lr)
    .Formula = "=IF(H2>I2,""BUY"",""SELL"")"
    .Value = .Value
End With
Application.ScreenUpdating = True
End Sub

Open in new window


Click the button called "Buy OR Sell" on Sheet2 to run the code.
Book1.xlsb

Author

Commented:
Thnx Neeraj for ur great support
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
You're welcome Sachin!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial