Consulting

Results 1 to 10 of 10

Thread: Solved: Copy based on multiple condition

  1. #1
    VBAX Regular
    Joined
    Jul 2010
    Posts
    25
    Location

    Solved: Copy based on multiple condition

    Is there a way I can copy data from one sheet to other when 3 conditions are met, out of which 2 are user input and third is completed field should be blank
    I have a job sheet which has got a lot of column; however I need to get only 3 filed from this sheet to be copied into new sheet.

    Can this be done, as currently I am using auto filter and copy paste manually.
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Brute force approach

    [vba]

    Public Sub ProcessData()
    Dim Lastrow As Long
    Dim Nextrow As Long
    Dim i As Long

    Application.ScreenUpdating = False

    With Worksheets("Job Sheet")

    Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    Nextrow = 5
    For i = 2 To Lastrow

    If .Cells(i, "D").Value2 = Worksheets("Summary").Range("B2") And _
    .Cells(i, "C").Value2 <= Worksheets("Summary").Range("C2") Then

    Nextrow = Nextrow + 1
    Worksheets("Summary").Cells(Nextrow, "A").Value2 = .Cells(i, "C").Value2
    Worksheets("Summary").Cells(Nextrow, "B").Value2 = .Cells(i, "A").Value2
    End If
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jul 2010
    Posts
    25
    Location
    sorry nothing is happening...

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi there,

    Reference: "These 2 filed (sic) are entered by user. The Date fill is the max date the report should show"

    Is the 'max date' to reference the 'Start Date' or 'Due Date' column on the 'Job Sheet' worksheet?

  5. #5
    VBAX Regular
    Joined
    Jul 2010
    Posts
    25
    Location
    thanks for looking into this, i have got the code do almost what I want except i want to clear the form every time i change Max date or employee id...hope you can help?

    [VBA]Sub FindEmployee()

    Dim SrchRows As Integer
    Dim SrchRnge As String
    Dim EID As String
    Dim MyDate As Date

    EID = Sheets("Summary").Range("B1")
    MyDate = Sheets("Summary").Range("B2")
    SrchRows = Sheets("Job Sheet").UsedRange.Rows.Count
    SrchRnge = Sheets("Job Sheet").UsedRange.Address

    If EID = "" Or MyDate = 0 Then Exit Sub

    For Each c In Sheets("job sheet").Range("D2" & SrchRows)

    If c = EID Then
    If DateValue(MyDate) >= DateValue(Sheets("Job Sheet").Range(c.Address).Offset(0, -1)) Then
    Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = _
    Sheets("job sheet").Range(Cells(c.Row, c.Column).Address).Offset(0, -1)
    Sheets("Summary").Range("B" & Rows.Count).End(xlUp).Offset(1, 0) = _
    Sheets("job sheet").Range(Cells(c.Row, c.Column).Address).Offset(0, -3)
    Sheets("Summary").Range("E" & Rows.Count).End(xlUp).Offset(1, 0) = _
    Sheets("job sheet").Range(Cells(c.Row, c.Column).Address).Offset(0, 5)
    End If
    End If

    Next c

    End Sub[/VBA]
    Attached Files Attached Files

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by yogin
    thanks for looking into this, i have got the code do almost what I want except i want to clear the form every time i change Max date or employee id...hope you can help?
    If I am understanding, right after...
    If EID = "" Or MyDate = 0 Then Exit Sub
    ...try...
    With ThisWorkbook.Worksheets("Summary")
        Range(.Cells(6, "A"), .Cells(.Rows.Count, "E")).ClearContents
    End With

  7. #7
    VBAX Regular
    Joined
    Jul 2010
    Posts
    25
    Location
    Thanks perfect...

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Yogin,
    When you post code, please tag it using the green VBA button to format it as shown.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Regular
    Joined
    Jul 2010
    Posts
    25
    Location
    hi mdmackillop,...sorry this is the first time i had put the code in...still learning VB.

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That's not VB yogin, that is forum facilities

    People like MD watch over so as to make it a better experience for all.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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