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
Bookmarks