+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: Macro for creating new workbook based on Decision Dates/Industry

  1. #1
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Thumbs up Macro for creating new workbook based on Decision Dates/Industry

    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.

    Attached Files Attached Files
    Last edited by sunilwadhwa; 01-23-2012 at 01:41 PM.

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: Macro for creating new workbook based on Decision Dates/Industry

    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]

  3. #3
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro for creating new workbook based on Decision Dates/Industry

    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



    Quote Originally Posted by arlu1201 View Post
    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

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: Macro for creating new workbook based on Decision Dates/Industry

    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]

  5. #5
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro for creating new workbook based on Decision Dates/Industry

    The data is on sheet8. The error message I get is -

    Runtime Error "1004"
    Application defined or Object defined error

    Then when I hit "Debug" option it takes me to this code -

    lrow = .Range("A" & Rows.Count).End(xlUp).Row




    Quote Originally Posted by arlu1201 View Post
    Is your data on worksheet 1? Whats the error msg?

  6. #6
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: Macro for creating new workbook based on Decision Dates/Industry

    Will your sheet name remain constant always? Then you can change this line -
     With Thisworkbook.worksheets(1)
    to this
     With ThisWorkbook.Worksheets("sheet8")
    I am currently out of station so working from here.
    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]

  7. #7
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro for creating new workbook based on Decision Dates/Industry

    I have attached screenshots of the error messages I get. Hope you can help


    Quote Originally Posted by arlu1201 View Post
    Will your sheet name remain constant always? Then you can change this line -
     With Thisworkbook.worksheets(1)
    to this
     With ThisWorkbook.Worksheets("sheet8")
    I am currently out of station so working from here.
    Attached Files Attached Files

  8. #8
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: Macro for creating new workbook based on Decision Dates/Industry

    Ohhhhh.....i found the error....i seriously did ....
    Change this line
    lrow = .Range("A" & Rows.Count).End(xlUp).Row
    to
     lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    See the dot before rows.
    Also, you have to use
    With ThisWorkbook.Worksheets("Pipeline (Current wk)")
    in your code line.
    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]

  9. #9
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro for creating new workbook based on Decision Dates/Industry

    Just to remind you - my data starts from Row 14 column M. Not sure if this is the reason for the error.....just guessing


    Quote Originally Posted by arlu1201 View Post
    Will your sheet name remain constant always? Then you can change this line -
     With Thisworkbook.worksheets(1)
    to this
     With ThisWorkbook.Worksheets("sheet8")
    I am currently out of station so working from here.

  10. #10
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro for creating new workbook based on Decision Dates/Industry

    I get a new error now on this code -

    .Worksheets("Sheet3").Delete

  11. #11
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: Macro for creating new workbook based on Decision Dates/Industry

    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]

  12. #12
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro for creating new workbook based on Decision Dates/Industry

    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.

  13. #13
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,383

    Re: Macro for creating new workbook based on Decision Dates/Industry

    Just change this line -
     If .Range("U" & i).Value = Date + 7 Then
    to
     If .Range("U" & i).Value <= Date + 7 Then
    If there is no data corresponding to the dates less than next thursday's date, you wont see any data in the file.
    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]

  14. #14
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro for creating new workbook based on Decision Dates/Industry

    Hi,

    Got a new error message on this code now -

    Workbooks(FName).Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = SName

    Quote Originally Posted by arlu1201 View Post
    Just change this line -
     If .Range("U" & i).Value = Date + 7 Then
    to
     If .Range("U" & i).Value <= Date + 7 Then
    If there is no data corresponding to the dates less than next thursday's date, you wont see any data in the file.

  15. #15
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro for creating new workbook based on Decision Dates/Industry

    Bump no response



    Quote Originally Posted by sunilwadhwa View Post
    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0