+ Reply to Thread
Results 1 to 5 of 5

Vlookup loop vba

Hybrid View

  1. #1
    Registered User
    Join Date
    06-30-2012
    Location
    new york
    MS-Off Ver
    Excel 2003
    Posts
    4

    Vlookup loop vba

    Hello,

    I'm relatively new to using vba. But, basically what I have now is a list of dates in column A on sheet 1. In every seventh column there is another list of dates (i.e. G, M,... etc.). I would like to write something in vba that will pull rates from column B in sheet 2 (for which there are dates in column A), and enter them in sheet 1 two columns to the right of the associated dates (C, I, O,... etc). I know this might sound a bit unclear so please ask me any questions that might clear it up. Thank you.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,040

    Re: Vlookup loop vba

    Can you upload example workbook with your inputs and desired output?
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    06-30-2012
    Location
    new york
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Vlookup loop vba

    Here's an example of what the file looks like. Unfortunately I don't have the actual file on this computer which will have significantly more data
    Attached Files Attached Files

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,040

    Re: Vlookup loop vba

    Here, try this:

    Sub transfer_date()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim i As Integer
    Dim j As Integer
    Dim LastCol As Integer
    Dim LastRow As Integer
    
    
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets("Sheet2")
    
    LastCol = ws1.Range("IV1").End(xlToLeft).Column
    
    For i = 0 To LastCol
        If ws1.Range("A1").Offset(0, i).Value = "DATE" Then
                LastRow = ws1.Range("A1").Offset(65535, i).End(xlUp).Row
                For j = 1 To LastRow
                    ws1.Range("A1").Offset(j, i + 2).Value = Application.SumIf(ws2.Range("A1:A65535"), ws1.Range("A1").Offset(j, i).Value, ws2.Range("B1:B65536"))
                Next j
        End If
    Next i
    
    End Sub
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-30-2012
    Location
    new york
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Vlookup loop vba

    Sorry for taking so long to get back but is there a way I could alter this to work for dates that don't match up exactly? I'd like it to still pull the data if the dates are witihin three days of each other ideally

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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