Code Error

  • I am using the attached code however when my database query does not return any data I dont want the Dim function to perform. can anyone help?


  • Re: Code Error


    Hi


    not quite sure what you mean by the Dim function not performing. Dim is simply a way of declaring a variable. Do you mean that you don't want the LastRow variable to be set, and that the subsequent code should not run if LastRow is Null or zero?


    Robert

  • Re: Code Error


    Quote from Robert B

    Hi


    not quite sure what you mean by the Dim function not performing. Dim is simply a way of declaring a variable. Do you mean that you don't want the LastRow variable to be set, and that the subsequent code should not run if LastRow is Null or zero?


    Robert


    Yes, sorry new to these codes

  • Re: Code Error


    Hi


    I assume your query will always return something even if it is Null, so try


    Code
    Dim Last_Row As Long 
            Last_Row = Range("A65535").End(xlUp).Row 
    If LastRow =<1 Then 
    Goto 10 
    End If
        Range("I2:BU2").AutoFill Destination:=Range("I2:BU" & Last_Row), Type:=xlFillDefault 
    
    
    10


    if this is not the case then try



    Robert

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!