PDA

View Full Version : IF function



Chris_AAA
09-16-2014, 04:47 AM
Hi All

Im wondering if you are able to help on the below...... or advise of any ideas.....

I have the below code which performs a vlookup and fills down - as per code below.

However on a monday, given a weekend there might not be any data to lookup - and therefore debugs, because there is nothing to fill down.


Im revisiting some of my current code and fixing the gaps such as this one, and trying to learn from it. Im extremely new to VBA, so please excuse my ignorance.


ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[2],'DATA!C[-1]:C[30],32,)"
lnglastrow = ActiveSheet.UsedRange.Rows.Count
Selection.AutoFill Destination:=Range("C2:C" & lnglastrow)

I am guessing the code needs to read before the above code..... 'If no data on row 2, then skip this process and move to the next line of code after the vlookup piece'

Im looking forward to any replies....

Thank you.

Bob Phillips
09-16-2014, 05:10 AM
With Range("C2")

.FormulaR1C1 = "=VLOOKUP(RC[2],'DATA!C[-1]:C[30],32,)"
If Application.CountA(Rows(3).Cells) > 0 Then

lnglastrow = ActiveSheet.UsedRange.Rows.Count
.AutoFill Destination:=.Resize(lnglastrow)
End If
End With

Chris_AAA
09-16-2014, 06:08 AM
Hi XLD

Thanks for the feedback....

It still debugs on this line of code....


.FormulaR1C1 = "=VLOOKUP(RC[2],'DATA!C[-1]:C[30],32,)"

Does it require anything before .Formula??

Bob Phillips
09-16-2014, 08:38 AM
You need to remove the apostrophe before DATA or add another one after it.

Chris_AAA
09-16-2014, 08:44 AM
Oh god, I missed that.

The code works perfectly.


Thank you so much for your help.....

Have a great day.