0

I have a excel workbook name prog.xls in D:\ in sheet1 i have 3 column contains n number of records with first row as a column heading column1-Name,Column2-DOB,Column3-Email_Id. I want to match DOB to current date to check whose Birthday is today and want to copy corresponding Email_Id to sheet2.

Below Is My code

MyDate=Date
Set myxl = createobject("excel.application")
myxl.Workbooks.Open "D:\prog.xls"
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
Row=mysheet.UsedRange.Rows.Count
For i= 2 to Row

If Mysheet.cells(i,2).value =Day(MyDate)&"/"&Month(MyDate) Then

above code is working fine,but its not complete. it will only check. but how to store corresponding Email_ID into sheet2. Please help me. Thanks in Advance

1 Answer 1

0

Please try the below code and let me know.

MyDate=Date

Set myxl = createobject("excel.application")
myxl.Workbooks.Open "D:\Form.xls"
myxl.application.Visible = True
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
Row=mysheet.UsedRange.Rows.Count

j=1
For i= 2 to Row

If mysheet.cells(i,2).value =Day(MyDate)&"/"&Month(MyDate) Then
Email=mysheet.cells(i,3).value

set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet2")
mysheet.cells(j,1)=Email
j=j+1
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
End If
Next
myxl.ActiveWorkbook.save
myxl.quit
Set myxl =Nothing

Thanks

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.