PDA

View Full Version : Insert Value When A Conditin is Met



Ajit
09-10-2013, 10:28 PM
Dear All,

I've just joined this forum and feel excited to be a part of this. I'm looking for a VB code to have a value being inserted when a condition is being met. For eg., in the attached file, values under Col F i.e Header Comment would have to turn / get inserted as "Same Day Cancel" when the macro is run - header 'd' for a value 'C' in col D.

All I know is that the above can be accomplished through loops (correct me if I'm wrong, pls) and becomes a bouncer when I attempt to understand such loops as & when I read somewhere! 1208

Your help is immensely appreciated. Thanks again in advance. Also, request you to pls share any material on VB to pick things up at a relatively faster rate. I've downloaded a number of soft copies on VBA but the pedagogy isn't too appealing to me unfortunately.

Thanks a ton for your help again! :)

Admin
09-11-2013, 06:34 AM
Hi Ajit,

Welcome to ExcelFox !!

You can accomplish by inserting the formula in F4 and copied down,

=IFERROR(IF(D4="C","Same Day Cancel",""),"")

Ajit
09-12-2013, 11:25 AM
Hi Admin!

Thanks very much for your reply. However, I'm looking for a VB code to do the same in an excel sheet. For eg., I want a loop to be written in VB code such that the loop looks at the whole of a range...say Cell C3 to C5000 and gives the output as "Same Day Cancel" in Col E for any of the cells found in Col C. I've managed to put the below loop in but doesn't work for a given range:



Sub test()

If Range("C3:C5000").Value = "C" Then Range("E3:E5000").Value = "Same Day Cancel"

End Sub

It only works for a given Cell i.e C3 but not C3:C5000.

Thanks much for your help. Would you be able to help me put in a loop pls?

-Ajit

Admin
09-12-2013, 06:58 PM
Hi

Try


Sub kTest()

With Range("d3:d5000")
.Offset(, 2).Value = Evaluate("IFERROR(IF(" & .Address & "=""C"",""Same Day Cancel"",""""),"""")")
End With

End Sub