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

Thread: VBA to copy data into other sheets based on specific criteria’s

  1. #1
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    VBA to copy data into other sheets based on specific criteria’s

    Hello,
    I need your help in preparing a Dash Board. I have an excel file with data pulled from external source & have lot of dump in it. I am looking for specific data that need to be pulled from that dump and saved in another sheet of the same file (as in example file).

    In the Received Sheet:
    1. It should prompt for the date and after entering the date (21- Jan in example file) it should fetch the data of Team A to Team E and paste it in Received Sheet based on Column L (Insert_time).
    2. If this sheet is not available it should create a new one, if the sheet is already available then it need to clear the old data and paste the new one.

    In the Closed Sheet:
    1. It should prompt for the date and after entering the date (21- Jan in example file) it should fetch the data of Team A to Team E and paste it in Closed Sheet based on Column N (Close_Time) & Column U (Status of only “Closed”, “Closure Pending”, “Verified Closed”)
    2. If this sheet is not available it should create a new one, if the sheet is already available then it need to clear the old data and paste the new one.

    In Open Sheet:
    1. It should fetch the data of Team A to Team E based on Column U (Status of only “Open”, “New”, “pending”)

    I have attached the sample spread sheet for your reference. Sorry if my request is not clear.

    Thanks in advance for your help!!

    Regards,
    Humac
    Last edited by humacdeep; 01-31-2012 at 07:29 AM. Reason: Solved

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

    Re: VBA to copy data into other sheets based on specific criteria’s

    Your sample data shows Teams F, G & X along with Teams A to E. What should be done for these 3 teams?
    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
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    Hi Arlette,

    Thanks for your response. It should ignore all other teams apart from Team A to Team E. I may even have more teams in the orginal data but looking for only specific teams data in the result.

    Regards,
    Humac

  4. #4
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    Hi Arlette,

    Did you get a chance to look into this?

    Regards,
    Humac

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

    Re: VBA to copy data into other sheets based on specific criteria’s

    Sorry, i have another question - in your first post, you have mentioned that the code needs to prompt for the date twice, will the dates in both prompts be the same? Can the prompt be given only once in that case?
    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]

  6. #6
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    Yes, the date is same for both prompts & can the prompt can be given once.

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

    Re: VBA to copy data into other sheets based on specific criteria’s

    While working on the code for your request, i landed upon another doubt - will the sheets Received, Closed and Open be blank when the data will be copied over? So i can just search for the date provided and then copy the contents over from sheet1 to the required sheet?
    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]

  8. #8
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    No, I will use the same template daily. So the code need to clear the existing data in Received, Closed and Open sheets & then copy the data.

    Also all the Received, Closed and Open sheets should have the Heading from Row1 of the Sheet1.

  9. #9
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    Hello Arlette,

    Any luck on this?

    Regards,
    Humac

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

    Re: VBA to copy data into other sheets based on specific criteria’s

    Humac, last nite the forum was down for some time during the upgrade to the new server. I will try something now and post it.
    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]

  11. #11
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    No Prob... Thanks!!

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

    Re: VBA to copy data into other sheets based on specific criteria’s

    Use this code - it takes care of all 3 requirements -
    Option Explicit
    Dim userdate As Date
    Dim lrow As Long
    Dim i As Long
    Dim lastrow As Long
    
    Sub copy_data()
    
    Application.ScreenUpdating = False
    
    userdate = InputBox("Please enter the date in format dd-mmm", "Enter Date")
    
    With Worksheets("Sheet1")
        If Not Evaluate("ISREF('Received'!A1)") Then
            Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Received"
            .Rows("1:1").Copy Worksheets("Received").Range("A1")
        Else
            lastrow = Worksheets("Received").Range("A" & Rows.Count).End(xlUp).Row
            Worksheets("Received").Range("A2:U" & lastrow).ClearContents
        End If
        
        lrow = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 2 To lrow
            If .Range("L" & i).Value = userdate Then
                If .Range("S" & i).Value = "Team A" Or .Range("S" & i).Value = "Team B" Or .Range("S" & i).Value = "Team C" Or _
                    .Range("S" & i).Value = "Team D" Or .Range("S" & i).Value = "Team E" Then
                        .Range("A" & i & ":U" & i).Copy Worksheets("Received").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                End If
            End If
        Next i
        
        If Not Evaluate("ISREF('Closed'!A1)") Then
            Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Closed"
            .Rows("1:1").Copy Worksheets("Closed").Range("A1")
        Else
            lastrow = Worksheets("Closed").Range("A" & Rows.Count).End(xlUp).Row
            Worksheets("Closed").Range("A2:U" & lastrow).ClearContents
        End If
        
        For i = 2 To lrow
            If .Range("N" & i).Value = userdate Then
                If .Range("S" & i).Value = "Team A" Or .Range("S" & i).Value = "Team B" Or .Range("S" & i).Value = "Team C" Or _
                    .Range("S" & i).Value = "Team D" Or .Range("S" & i).Value = "Team E" Then
                    If .Range("U" & i).Value = "Closed" Or .Range("U" & i).Value = "Closure Pending" Or .Range("U" & i).Value = "Verified closed" Then
                        .Range("A" & i & ":U" & i).Copy Worksheets("Closed").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                    End If
                End If
            End If
        Next i
        
        If Not Evaluate("ISREF('Open'!A1)") Then
            Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Open"
            .Rows("1:1").Copy Worksheets("Open").Range("A1")
        Else
            lastrow = Worksheets("Open").Range("A" & Rows.Count).End(xlUp).Row
            Worksheets("Open").Range("A2:U" & lastrow).ClearContents
        End If
        
        For i = 2 To lrow
            If .Range("S" & i).Value = "Team A" Or .Range("S" & i).Value = "Team B" Or .Range("S" & i).Value = "Team C" Or _
                    .Range("S" & i).Value = "Team D" Or .Range("S" & i).Value = "Team E" Then
                    If .Range("U" & i).Value = "New" Or .Range("U" & i).Value = "Open" Or .Range("U" & i).Value = "Pending" Then
                        .Range("A" & i & ":U" & i).Copy Worksheets("Open").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                    End If
            End If
        Next i
        
    End With
    
    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]

  13. #13
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    Thanks Arlette, I will test and let you know the result.

  14. #14
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    Hello Arlette,

    I have tested the code in Orgianl data, it is creating all the required sheets but once I enter the date it is not copying data in Received & Closed Sheets. I have attached the sample sheet. please have a check.

    I have entered 25-Jan as Date.

    Regards,
    Humac
    Last edited by humacdeep; 01-31-2012 at 07:32 AM.

  15. #15
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    173

    Re: VBA to copy data into other sheets based on specific criteria’s

    Its working as desired in DashBoard.Xls (sample data) & not in DashBoard_1.xls (Orginal Data), the only difference is between two files is Table format. Does this code will not work if the data in Sheet1 is in Table format?

+ 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