Hi,
Can someone please help me create a macro with the attached Excel (sample)Spreadsheet.
I receive this file every Thursday. Then I filter on "Decision Date" (column U)with "Is Before or equal to" and select next Thursday's date. Once I have done that I know this is the list of opportunities which is nearing/past their decision date.
I now filter on Ind Name (Column X) and open a new workbook and paste data on each worksheet based on an Industry. There are 4 industries - Consumer Products, Life Sciences, Retails, Travel and Transportation. So my new sheet has for tabs and data pasted on these respective tabs.
Can someone please help me create a macro so that I don't have to do this manually every week.
Spreadsheet attached for your reference.
![]()
Last edited by sunilwadhwa; 01-23-2012 at 01:41 PM.
Copy this code in a blank module (Press on Alt + F11, right click on Microsoft excel objects on the left hand side, select insert->module).Option Explicit Dim FName As String Dim SName As String Dim lrow As Long Dim i As Long Sub filter_rows() Application.DisplayAlerts = False Application.ScreenUpdating = False Workbooks.Add ActiveWorkbook.SaveAs ("Output File") FName = ActiveWorkbook.Name With ThisWorkbook.Worksheets(1) lrow = .Range("A" & Rows.Count).End(xlUp).Row For i = 15 To lrow If .Range("U" & i).Value = Date + 7 Then SName = .Range("X" & i).Value If Not Evaluate("ISREF('" & SName & "'!A1)") Then Workbooks(FName).Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = SName .Rows("14:14").Copy Workbooks(FName).Worksheets(SName).Range("A1") End If .Rows(i & ":" & i).Copy Workbooks(FName).Worksheets(SName).Range("A" & Rows.Count).End(xlUp).Offset(1, 0) End If Next i End With With Workbooks(FName) .Worksheets("Sheet1").Delete .Worksheets("Sheet2").Delete .Worksheets("Sheet3").Delete End With Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Hi Arlette,
I tried running it but I get "Run Time" error message and when I hit debug - it highlights lrow = .Range("A" & Rows.Count).End(xlUp).Row
in yellow.
It does create a new file named "Output file" which is blank.
Please help!!!!
I see that you are from Bangalore. If you could give me your mobile # so that I could talk to you would be nice.
Regards,
Sunil Wadhwa
Is your data on worksheet 1? Whats the error msg?
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Will your sheet name remain constant always? Then you can change this line -to thisWith Thisworkbook.worksheets(1)I am currently out of station so working from here.With ThisWorkbook.Worksheets("sheet8")
Last edited by arlu1201; 01-19-2012 at 08:53 AM.
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Ohhhhh.....i found the error....i seriously did ....
Change this linetolrow = .Range("A" & Rows.Count).End(xlUp).RowSee the dot before rows.lrow = .Range("A" & .Rows.Count).End(xlUp).Row
Also, you have to usein your code line.With ThisWorkbook.Worksheets("Pipeline (Current wk)")
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
I get a new error nowon this code -
.Worksheets("Sheet3").Delete
I was just using that line to remove the usual sheets Sheet1,2 and 3 in the file. If you dont have that sheet in the workbook, just remove that line of code.
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
It does not give me any error message when I run the macro this time but the output file is blank without any data on it.
Just change this line -toIf .Range("U" & i).Value = Date + 7 ThenIf there is no data corresponding to the dates less than next thursday's date, you wont see any data in the file.If .Range("U" & i).Value <= Date + 7 Then
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks