Consulting

Results 1 to 9 of 9

Thread: Solved: VLOOKUP Code

  1. #1

    Solved: VLOOKUP Code

    Hello,

    I am trying to move my formulas into VBA so that my large spreadsheet runs faster:

    On Sheet Paste Full Report Here in column G i have the following formula:
    =IFERROR(VLOOKUP(A5,'Managers-Shifts'!$A$2:$D$999985,4,FALSE),"New Employee")
    This continues down to Line 16000. How can I write this in VBA to calculate?
    Note: A5 is a variable that changes depending on the row the formula is located.

    I am very new to this and learn best by seeing an example and given labels.

    Thanks!
    Q

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    example of workbook would be useful
    ------------------------------------------------
    Happy Coding my friends

  3. #3
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    Maybe:

    [VBA]ActiveWorkbook.Sheets(1).Activate
    Range("A1").Activate

    Range("G2").Formula = "=IFERROR(VLOOKUP(A5,'Managers-Shifts'!$A$2:$D$999985,4,FALSE),"New Employee")"

    Range("G2").Select
    Selection.AutoFill Destination:=Range("G2:G" & UsedRange.Rows.Count), Type:=xlFillDefault[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  4. #4

    Thank you

    I get an error with the code above, attached is a simple version of the worksheet
    Match the ID numbers and autofill name of manager
    Attached Files Attached Files

  5. #5
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [vba]Sub formulaToCells()
    ActiveWorkbook.Sheets(2).Activate
    Range("A1").Activate
    Dim cell As Range
    Dim rangeToFill As String
    rangeToFill = "G2:G" & Range("G:G").Rows.Count
    Application.ScreenUpdating = False
    For Each cell In Range(rangeToFill)
    cell.Formula = "=IFERROR(VLOOKUP(A5,'Managers-Shifts'!$A$2:$D$999985,4,FALSE),""New Employee"")"
    Next cell
    Application.ScreenUpdating = True
    End Sub[/vba]
    ------------------------------------------------
    Happy Coding my friends

  6. #6
    Ok it works, however is there a way for A5 to change to match the number for each row the formula is in?

  7. #7
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [VBA]"=IFERROR(VLOOKUP(A" & cell.Row & ",'Managers-Shifts'!$A$2:$D$999985,4,FALSE),""New Employee"")"
    [/VBA]
    ------------------------------------------------
    Happy Coding my friends

  8. #8
    THANKS! and I have already been able to adapt this to the other formulas I need!

  9. #9
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    glad to help
    ------------------------------------------------
    Happy Coding my friends

Posting Permissions

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