Consulting

Results 1 to 5 of 5

Thread: IF function

  1. #1

    IF function

    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.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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??

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to remove the apostrophe before DATA or add another one after it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Oh god, I missed that.

    The code works perfectly.


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

    Have a great day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •