PDA

View Full Version : VBA help loop until & IF formula



Spaceballs
02-15-2018, 05:51 PM
Hello, thanks for looking

I have a worksheet with a column full of dates.
I have a cell with a control date
I also need a column with a formula

Column B (starting at cell 5) has dates. The column updates weekly and the number of rows is dynamic. This is where the loop comes in.

C2 has a static date

Column F (starting at cell 5) would have the formula
=IF ($C $2>B5, "over", "in")

I have tried to Frankenstein different code from forums but Excel doesn't seem to like the formula.

Help is greatly appreciated.

yujin
02-16-2018, 02:02 AM
Hi, Spaceballs. I wonder if this is what you want but try it.


Sub Macro1()
Range("F5:F" & Rows.Count).ClearContents
Range("F5").Formula = "=IF($C$2>B5,""over"",""in"")"
Range("F5:F" & Range("B" & Rows.Count).End(xlUp).Row).FillDown
End Sub

p45cal
02-16-2018, 05:26 AM
or combine the last two lines:

Sub Macro2()
Range("F5:F" & Rows.Count).ClearContents
Range("F5:F" & Range("B" & Rows.Count).End(xlUp).Row).Formula = "=IF($C$2>B5,""over"",""in"")"
End Sub

yujin
02-16-2018, 06:16 AM
Yeah, I've learned from you.
Thanks p45cal!