[/FONT]Sub ADEployee()
Dim ld1 As Worksheet, ld2 As Worksheet, emp As Worksheet, id1 As String, Job As String, id2 As String, sid As String, sdate As Date, edate As Date, empdate As Date
Set ld1 = ThisWorkbook.Sheets("1ld")
Set ld2 = ThisWorkbook.Sheets("2ld")
Set emp = ThisWorkbook.Sheets("emp")
lr1 = ld1.Cells(Rows.Count, 11).End(xlUp).Row
lr2 = ld2.Cells(Rows.Count, 11).End(xlUp).Row
elr = emp.Cells(Rows.Count, 1).End(xlUp).Row
elc = emp.Cells(1, Columns.Count).End(xlToLeft).Column
lc1 = ld1.Cells(1, Columns.Count).End(xlToLeft).Column
lc2 = ld2.Cells(1, Columns.Count).End(xlToLeft).Column
e = 2
'column varilables
k = 11
v = 22
w = 23
xvar = 24
yvar = 25
x1 = 3
x2 = 3
' text to columns
'employee
emp.Activate
emp.Range(Cells(1, 1), Cells(1, elc)).Select
Selection.Font.Bold = True
emp.Cells(1, 2).Select
emp.Range(Cells(2, 1), Cells(elr, 1)).Select
Selection.Texttocolumns Destination:=Range("A2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Selection.NumberFormat = "000000"
'1ld
ld1.Activate
ld1.Range(Cells(2, 1), Cells(2, lc1)).Select
Selection.Font.Bold = True
ld1.Cells(3, k).Select
ld1.Range("K3:K" & lr1).Select
Selection.Texttocolumns Destination:=Range("K3"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Selection.NumberFormat = "000000"
'2ld
ld2.Activate
ld2.Range(Cells(2, 1), Cells(2, lc2)).Select
Selection.Font.Bold = True
ld2.Cells(3, k).Select
ld2.Range("k2:K" & lr2).Select
Selection.Texttocolumns Destination:=Range("A2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Selection.NumberFormat = "000000"
' sort
Call sortids
Call SortEmp
'loop 1
Do
DoEvents
sid = emp.Cells(e, 1)
empdate = emp.Cells(e, 5)
Job = emp.Cells(e, 7)
'loop 2
On Error Resume Next
id1 = ld1.Cells(x1, k)
id2 = ld2.Cells(x2, k)
lookingnumber = Empty
'choosing case number
If Not Application.IsNumber(Application.WorksheetFunction.Match(emp.Cells(e, 1), ld1.Range("k3:k1000000"), 0)) Then
lookingnumber = 2
End If
If Not Application.IsNumber(Application.WorksheetFunction.Match(emp.Cells(e, 1), ld2.Range("k3:k1000000"), 0)) Then
lookingnumber = 1
End If
Select Case lookingnumber
Case 1
ld1.Cells(1, k) = sid
sdate = ld1.Cells(1, w)
edate = ld1.Cells(1, yvar)
sr = Application.WorksheetFunction.Match(ld1.Cells(1, k), ld1.Range("k3:k100000"), 0) + 2
er = Application.WorksheetFunction.CountIf(ld1.Range("k3:k100000"), ld1.Cells(1, k)) + sr - 1
For x1 = sr To er
If edate = empdate Then
ld1.Cells(x1, yvar) = Job
End If
Next x1
Case 2
ld2.Cells(1, k) = sid
sdate = ld2.Cells(1, w)
edate = ld2.Cells(1, yvar)
sr = Application.WorksheetFunction.Match(ld2.Cells(1, k), ld2.Range("k3:k100000"), 0) + 2
er = Application.WorksheetFunction.CountIf(ld2.Range("k3:k100000"), ld2.Cells(1, k)) + sr - 1
For x2 = sr To er
If edate = empdate Then
ld2.Cells(x2, yvar) = Job
End If
Next x2
End Select
e = e + 1
x1 = x1 + 1
x2 = x2 + 1
Loop Until e = elr + 1
End Sub
[FONT=Verdana]