+ Reply to Thread
Results 1 to 6 of 6

Loop through column to find EID then find date and paste corresponding data

Hybrid View

  1. #1
    Registered User
    Join Date
    04-27-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    14

    Loop through column to find EID then find date and paste corresponding data

    Hi Experts,

    I am new to vba and would like to seek help in exporting my class attendance data into an existing csv file that serves as database. What i need to do is first find if the EID (trainee ID) is already in the database by looking through column E of the csv file and if found, i need to look at the dates in row 1 and paste the corresponding data for that trainee. i have already created a code to export trainee data to a registry database but it is with the assumption that the trainee is not in that db yet. Below is a snapshot of the table i need to export into the attendance csv file.

    tracker.PNG


    Option Explicit
    Sub ExportrReg()
        
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        
        Dim wbk2 As Workbook
        Dim s1, rReg As Worksheet
        Dim x, i, FinalRow As Long
        Dim thisvalue As String
        Set wbk2 = Workbooks.Open(ThisWorkbook.Worksheets("Info").Range("A2").Value)
        Set s1 = wbk2.Sheets("RosterRegistry")
        Set rReg = ThisWorkbook.Worksheets("Roster Registry")
    
        With rReg
            ' Find the last row of data in Column "A"
            FinalRow = .Cells(.Rows.Count, "A").End(xlUp).Row
            ' Loop through each row
            For x = 2 To FinalRow
                ' Decide if to copy based on column A
                thisvalue = .Cells(x, 1).Value
                If thisvalue <> "" Then
                    i = s1.Cells(s1.Rows.Count, 1).End(xlUp).Row + 1
    
                    s1.Cells(i, 1).Value = thisvalue
                    s1.Cells(i, 2).Value = .Cells(x, 2).Value
                    s1.Cells(i, 3).Value = .Cells(x, 3).Value
                    s1.Cells(i, 4).Value = .Cells(x, 4).Value
                    s1.Cells(i, 5).Value = .Cells(x, 5).Value
                    s1.Cells(i, 6).Value = .Cells(x, 5).Value
                    s1.Cells(i, 7).Value = .Cells(x, 7).Value
                    s1.Cells(i, 8).Value = .Cells(x, 8).Value
                    s1.Cells(i, 9).Value = .Cells(x, 9).Value
                    s1.Cells(i, 10).Value = .Cells(x, 10).Value
                    s1.Cells(i, 11).Value = .Cells(x, 11).Value
                    s1.Cells(i, 12).Value = .Cells(x, 12).Value
                End If
            Next x
        End With
        wbk2.Close savechanges:=True
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Loop through column to find EID then find date and paste corresponding data

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    04-27-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    14

    Re: Loop through column to find EID then find date and paste corresponding data

    I have attached a sample file with a before and after tab though please note that output should be in another workbook. and i only have a few trainees in the list but the output file may have more and i need to look for the EIDs in the first tab, locate them on the output file before i copy over data. if the EID is not found, then i copy the data on the next available row.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Loop through column to find EID then find date and paste corresponding data

    This Macro will copy your data from your Data Dump to the active sheet.

    
    Sub Test()
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    LC = Cells(1, Columns.Count).End(xlToLeft).Column
        Range(Cells(2, 13), Cells(LR, LC)).FormulaR1C1 = _
    "=IF(ISNA(MATCH(RC5,'Class Data Dump'!C5,0)),"""",OFFSET('Class Data Dump'!R1C,MATCH(RC5,'Class Data Dump'!C5,0)-1,0))"
    Range(Cells(2, 13), Cells(LR, LC)).Value = Range(Cells(2, 13), Cells(LR, LC)).Value
    End Sub

  5. #5
    Registered User
    Join Date
    04-27-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    14

    Re: Loop through column to find EID then find date and paste corresponding data

    Thanks for the response. However, this code only copies the data...i need for it to find the matching date in row 1 and put in the data in that column.

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Loop through column to find EID then find date and paste corresponding data

    Ahh

    I begin to understand.

    
    Sub Test()
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    LC = Cells(1, Columns.Count).End(xlToLeft).Column
    For Student = 2 To LR
    For Entry = 13 To LR
    If Sheets("Class Data Dump").Cells(Student, Entry) <> "" Then
    
    x = Rows(1).Find(DateValue(Sheets("Class Data Dump").Cells(1, Entry).Value), LookIn:=xlValues, LookAt:=xlPart).Column
    
    y = Columns(5).Find(Sheets("Class Data Dump").Cells(Student, 5).Value, LookIn:=xlValues, LookAt:=xlWhole).Row
    
    Cells(y, x).Value = Sheets("Class Data Dump").Cells(Student, Entry)
    
    End If
    Next
    Next
    
    End Sub

+ 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. [SOLVED] find date string and paste into different column, same row
    By rdowney79 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-06-2014, 11:27 AM
  2. Replies: 3
    Last Post: 09-14-2013, 06:45 PM
  3. [SOLVED] Find the date and copy the values from the colum of the date find and paste to other sheet
    By nizzcmzph in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-20-2013, 10:03 AM
  4. find date in column A and copy, paste and transpose valuse
    By myguess21 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2012, 03:24 PM
  5. Loop to find, copy and paste data doesn't work
    By mazerinth in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2012, 09:07 AM
  6. Loop Macro to Find Minimum Date for Column Data
    By abpexcelforum in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-05-2011, 05:03 PM
  7. Loop to find cell, paste to new column. Turn 1 column into many.
    By d0tc0m in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-14-2011, 09:51 AM
  8. Replies: 1
    Last Post: 05-06-2011, 03:08 AM

Tags for this Thread

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