+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24

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

  1. #16
    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

    In Dashboard_1, you have marked the code for Closed and Open in green (commented it). This will prevent the code from running. Any specific reason why you have done so?
    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]

  2. #17
    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 commented that to see what all are executing in 3 sheets, only Open sheet is populating the data. Even if I execute the entire program its only populating data in Open sheet.

    Regards,
    Humac

  3. #18
    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

    The date format that you gave me in the dummy file was dd-mmm but in this file, its with a timestamp as well. So i just had to change a few things and got it working. Use this code -
    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 mm/dd/yy", "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
            .Rows("1:1").Copy Worksheets("Received").Range("A1")
        End If
        
        lrow = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 2 To lrow
            If .Range("L" & i).Value Like 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
        
        Worksheets("Received").Cells.EntireColumn.AutoFit
        
        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
            .Rows("1:1").Copy Worksheets("Received").Range("A1")
        End If
    
         For i = 2 To lrow
            If .Range("N" & i).Value Like 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
        
        Worksheets("Closed").Cells.EntireColumn.AutoFit
    
        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
            .Rows("1:1").Copy Worksheets("Received").Range("A1")
        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
        
        Worksheets("Open").Cells.EntireColumn.AutoFit
    
    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]

  4. #19
    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 a LOT & I appriciate your help!! Its working gr8.

    I got the point now, it populated data in Open sheet because it does not need date to validate the data .

  5. #20
    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

    Yes exactly. Next time ensure that you give the data in the same format as your original file, it works faster.
    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. #21
    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

    Sorry about that. Actually I have added the same way in the sample sheet, but due to my excel format it has been changed to dd-mmm . I make sure to double check it from now onwards.

  7. #22
    Registered User
    Join Date
    01-31-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    7

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

    hi all,

    i also have some problems when i want to copy data from other files.

    I want to use Command button to open folder, which contains .csv files. When i'll choose one of the files the aplication should put all the data from the file to an excel sheet 1.

    could you pls help me with this?

  8. #23
    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

    Karo,

    Welcome to Forum!!!

    As per the forum rules No. 2 you should not hijack others thread. Please submit a new thread and some one will get back to you.

    Forum Rule 2: Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread.


    Regards,
    Humac

  9. #24
    Registered User
    Join Date
    01-31-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    7

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

    sorry, i'm new here, it wont happen again

    karo

+ 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