Consulting

Results 1 to 4 of 4

Thread: Solved: Syntax error in formula...where am I going wrong?

  1. #1
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location

    Solved: Syntax error in formula...where am I going wrong?

    Hi
    I can define this formula in the excel cell quite happily and it works fine, returning the correct value from the 'Charge Rates Look-up' worksheet...

    [vba]VLOOKUP(A2&B2&D2,'Charge Rates Look-up'!$1:$100,7, False)[/vba]

    However, when I try to define it in a macro (see below) to make it apply to the entire column, there is a syntax error in the .Formula statement.

    [vba]Public Sub InsertLabourOrConsultancy()
    Dim iLastRow As Long
    With ActiveSheet
    .Cells(1, "J").Value = "Labour/Consultancy"
    iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("J2").Resize(iLastRow - 1).Formula = _
    "=VLOOKUP(A2&B2&D2,'Charge Rates Look-up'!$1:$100,7, False)"
    End With
    End Sub[/vba]

    Anyone know what I'm doing wrong? Must be something simple!
    Many thanks, Lester.

  2. #2
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location
    Actually, no...this aint gonna do what I need it to do (even if the syntax is corrected). It's gonna repeat A2&B2&D2, but i need it to move on by one each time; i.e. A3&B3&D3, then A4&B4&D4 and so on.

    Can someone help me with this problem, also?!

    Thanks again.

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Lester

    That formula should change the cell references as required.

    And the code works fine for me with no syntax errors.

  4. #4
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location
    Quote Originally Posted by Norie
    Lester

    That formula should change the cell references as required.

    And the code works fine for me with no syntax errors.
    I'm clearly having a bad day (continuation of a near-hit by a car whilst cycling to work this morning).

    You're absolutely right, Norie. It does work. Thanks for your efforts. Much appreciated.
    Regards
    Lester.

Posting Permissions

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