PDA

View Full Version : Need a Macro to do Daily task



krishhi
10-21-2011, 04:18 AM
Hi there,

I have a some small problem. Please look in to my query and if possible please show me a solution.

Here is a excel sample that i attached.

It contains data relates to Some cources, it has been collection every week in a month.

Here what i need to Filter the Excel with string "Main" on Column "E" then Copy the data in to Output sheet, as shown in the excel file. Then Go to "Master" Sheet then Filter on Column "E" with the strigns "Secondary and Third" then Filter on Column "F" with String "Main" then copy the data and paste it into Output Sheet as shown in the Excel. and For G Column viceversa.

I know we can do manually, but I need this to do every day to prinout the data and I have 100's of similar tasks. So, I need a macro to this task.

I try to figured it out but my thumbs down,.

Can any one help me on this?

Waiting for your kind reply.

krishhi
10-21-2011, 06:35 AM
Is this is a Hard Task or My Instructions are not clear?

mdmackillop
10-21-2011, 05:13 PM
Don't follow all your requirements, but here's a starter for you.

Option Explicit

Sub Test()

Dim wsM As Worksheet
Dim wsO As Worksheet
Dim Rng As Range
Dim tgt As Range



Set wsM = Sheets("Master")
Set wsO = Sheets("Sheet3")
Set Rng = wsM.Range("A1").CurrentRegion

wsM.Range("$D:$D").AutoFilter Field:=1, Criteria1:="Main"
Intersect(Rng, wsM.Range("$A:$C")).SpecialCells(xlCellTypeVisible).Copy wsO.Range("A2")
wsM.Range("$D:$D").AutoFilter
wsO.Range("A1") = "Main Course Interested"

wsM.Range("$F:$F").AutoFilter Field:=1, Criteria1:="Main"
Set tgt = wsO.Cells(Rows.Count, 1).End(xlUp).Offset(6)
Intersect(Rng, wsM.Range("$A:$C")).SpecialCells(xlCellTypeVisible).Copy tgt
wsM.Range("$F:$F").AutoFilter
tgt.Offset(-1) = "You may also be intersted in:"

End Sub

krishhi
10-21-2011, 08:35 PM
Don't follow all your requirements, but here's a starter for you.

Option Explicit

Sub Test()

Dim wsM As Worksheet
Dim wsO As Worksheet
Dim Rng As Range
Dim tgt As Range



Set wsM = Sheets("Master")
Set wsO = Sheets("Sheet3")
Set Rng = wsM.Range("A1").CurrentRegion

wsM.Range("$D:$D").AutoFilter Field:=1, Criteria1:="Main"
Intersect(Rng, wsM.Range("$A:$C")).SpecialCells(xlCellTypeVisible).Copy wsO.Range("A2")
wsM.Range("$D:$D").AutoFilter
wsO.Range("A1") = "Main Course Interested"

wsM.Range("$F:$F").AutoFilter Field:=1, Criteria1:="Main"
Set tgt = wsO.Cells(Rows.Count, 1).End(xlUp).Offset(6)
Intersect(Rng, wsM.Range("$A:$C")).SpecialCells(xlCellTypeVisible).Copy tgt
wsM.Range("$F:$F").AutoFilter
tgt.Offset(-1) = "You may also be intersted in:"

End Sub


Excellent and thank you very much. But I didn't see the data from Column F?

mdmackillop
10-22-2011, 05:26 AM
You should be able to do this from the sample posted. You don't show clearly what is filtered and where results go.
If you get stuck, please post your best attempts.

krishhi
10-22-2011, 10:43 PM
You should be able to do this from the sample posted. You don't show clearly what is filtered and where results go.
If you get stuck, please post your best attempts.

Hi,

Your code works very well. But it ignores the Column "E". Please check the attached Excel file.

Ouput sheet is the results i want.
Sheet3 is the results that I got from your code.

Thanks,

Aussiebear
10-23-2011, 12:55 AM
Is this is a Hard Task or My Instructions are not clear?

Its a little hard to test given that "Some Date" "Some Description", & "Some Course duration" are applied to all. Are we picking up the correct objects with the current code???? What about posting yet another workbook, with real dates, real course descriptions, and real course durations and we can test it again?

mdmackillop
10-23-2011, 04:58 AM
Please refer to our FAQ (http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_posthelp_faq_item), and my last response. We are here to assist, not do your work.

krishhi
10-24-2011, 08:37 AM
Please refer to our FAQ (http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_posthelp_faq_item), and my last response. We are here to assist, not do your work.

Very sorry if you take my reply in a wrong way.