+ Reply to Thread
Results 1 to 6 of 6

Loop through and lookup a specific value

Hybrid View

  1. #1
    Registered User
    Join Date
    09-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    72

    Loop through and lookup a specific value

    Hi All,

    I am posting a sample sheet with a simple version of my problem.

    Basicallly, I have 2 sheets. Sheet1 and Actual data. What I want to do is loop through the list of names in Sheet1 and pull the specific value for each one from actual data. This would be pretty easy but I'm struggling with looping through and also making sure that i'm pulling the right data.

    For example, the Person1 horses column in sheet1 should pull the number of horses associated with person1 from the actual data sheet.
    Attached Files Attached Files

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Loop through and lookup a specific value

    Not sure you need a macro for this. Here's an example with a formula approach and also with a pivot table.
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    09-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    72

    Re: Loop through and lookup a specific value

    Hi Jeffrey,

    I'd like it in a macro since it's going to be a part of another macro.

    Is that possible?

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Loop through and lookup a specific value

    How about with your sample

    Sub CreateTotals()
        Dim wsSrc As Worksheet: Set wsSrc = Sheets("Sheet1")
        Dim LastRow As Long
        Dim LastCol As Long
        Application.ScreenUpdating = False
        With wsSrc
            LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row - 2
            LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column - 2
            With .Range("C3").Resize(LastRow, LastCol)
                .Formula = "=SUMIFS('Actual Data'!$D:$D,'Actual Data'!$B:$B,$B3,'Actual Data'!$C:$C,C$1)"
                .Value = .Value
            End With
        End With
        Application.ScreenUpdating = True
    End Sub

  5. #5
    Registered User
    Join Date
    09-30-2019
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    72

    Re: Loop through and lookup a specific value

    So when I try to move it into my other macro i get "application defined or object defined error" on the .range("c3") line. Even when I update the sheets and everything. Any clue what's causing this?

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Loop through and lookup a specific value

    Sorry, don't know what's happening without seeing your work product.

+ 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. Change all loop to specific loop
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2015, 06:32 PM
  2. Loop for adding specific worksheets in specific workbooks
    By pankaj8219 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2013, 10:22 AM
  3. [SOLVED] Vlookup in UserForm - Get Input from listbox, Lookup in specific table from specific sheet
    By s2jrchoi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2013, 09:00 AM
  4. [SOLVED] Lookup & Loop
    By zhb12810 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-17-2012, 11:17 PM
  5. Replies: 2
    Last Post: 07-25-2012, 04:15 PM
  6. Excel 2007 : Lookup table Loop
    By grassasp in forum Excel General
    Replies: 2
    Last Post: 04-05-2011, 06:12 PM
  7. Lookup Loop
    By barnis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2010, 04:40 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