+ Reply to Thread
Results 1 to 3 of 3

Populate current sheet from different sheet more efficiently

  1. #1
    Registered User
    Join Date
    04-06-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    14

    Populate current sheet from different sheet more efficiently

    On a separate excel sheet named "Pricebook", I have near 1000 rows with 2 cells in each row I would like to populate the sheet I am working off when the code is typed in. The below code accomplishes this. Rather than programming 1000 variables is there a way to code this more efficiently. Any advice would be greatly appreciated.

    Thank You



    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim a As Range
    If Not Intersect(Target, Range("C21:C36")) Is Nothing Then
    For Each a In Intersect(Target, Range("C21:C36"))
    If a.Value = Worksheets("Pricebook").Range("A7") Then
    Application.EnableEvents = False
    Cells(a.Row, "E").Value = Worksheets("Pricebook").Range("B7")
    Cells(a.Row, "AA").Value = Worksheets("Pricebook").Range("I7")
    Application.EnableEvents = True
    End If
    Next a
    End If

    Dim b As Range
    If Not Intersect(Target, Range("C21:C36")) Is Nothing Then
    For Each b In Intersect(Target, Range("C21:C36"))
    If b.Value = Worksheets("Pricebook").Range("A8") Then
    Application.EnableEvents = False
    Cells(b.Row, "E").Value = Worksheets("Pricebook").Range("B8")
    Cells(b.Row, "AA").Value = Worksheets("Pricebook").Range("I8")
    Application.EnableEvents = True
    End If
    Next b
    End If

    Dim c As Range
    If Not Intersect(Target, Range("C21:C36")) Is Nothing Then
    For Each c In Intersect(Target, Range("C21:C36"))
    If c.Value = Worksheets("Pricebook").Range("A9") Then
    Application.EnableEvents = False
    Cells(c.Row, "E").Value = Worksheets("Pricebook").Range("B9")
    Cells(c.Row, "AA").Value = Worksheets("Pricebook").Range("I9")
    Application.EnableEvents = True
    End If
    Next c
    End If

    End Sub

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Populate current sheet from different sheet more efficiently

    Don't use code.

    Use this formula in E21:E36
    =IFERROR(VLOOKUP(C21,Pricebook!A:B,2,False),"")

    And this formula in AA21:AA36
    =IFERROR(VLOOKUP(C21,Pricebook!A:I,9,False),"")


    If you were to use code, the entirety would be
    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    04-06-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    14

    Re: Populate current sheet from different sheet more efficiently

    Amazing! Thank You! You saved me so much time.


    Quote Originally Posted by Bernie Deitrick View Post
    Don't use code.

    Use this formula in E21:E36
    =IFERROR(VLOOKUP(C21,Pricebook!A:B,2,False),"")

    And this formula in AA21:AA36
    =IFERROR(VLOOKUP(C21,Pricebook!A:I,9,False),"")


    If you were to use code, the entirety would be
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. save .xlsx from active sheet, with sheet name, same address of current workbook
    By Mikeswell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2014, 12:14 PM
  2. [SOLVED] VBA - Macro issue copy/paste line other sheet + duplicate current sheet
    By vcourbiere in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-17-2014, 12:06 PM
  3. Replies: 2
    Last Post: 10-22-2013, 08:04 AM
  4. Replies: 3
    Last Post: 02-20-2013, 12:54 AM
  5. [SOLVED] Pull needed data from 'task backlog' to populate 'current sprint' sheet
    By tek_9 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-06-2012, 06:10 PM
  6. [SOLVED] Excel VBA: Dropdown box selection in first sheet to populate 2nd sheet from 3rd sheet data
    By EMLalan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-07-2012, 09:46 AM
  7. Pulling Information in seperate sheet based on data in current sheet
    By joekunin in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-03-2009, 05:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1