Consulting

Results 1 to 3 of 3

Thread: Copy & Paste Based on Column Criteria

  1. #1
    VBAX Regular
    Joined
    Aug 2012
    Posts
    24
    Location

    Post Copy & Paste Based on Column Criteria

    Hi All,

    I am in need of some help formulating a macro that will allow me to copy data from one sheet to another based upon the a specific criteria. Basically, I have a workbook with the sheets "CopyFrom" and "CopyTo". On the sheet "CopyFrom", I have my data organized the following columns:

    A ----> "Ticker"
    B ----> "Description"
    C ----> "Asset Class"
    D ----> "Manager Style"
    On the sheet "CopyTo" I have filtered and transposed all of the individual manager styles found in Column D on the "CopyFrom" worksheet. From here I would like to copy all of the ticker symbols ("CopyFrom" ColA) that correspond to the criteria (Manager Style) set fourth in R1 of the "CopyTo" worksheet.

    I have attached a sample workbook with an example of how I would like the end result to turn out.

    Thank you in advance for your help. It is greatly appreciated.
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Try placing the following in your example file; it creates a new sheet each time and populates it:
    Sub blah()
    Set SourceSht = Sheets("CopyFrom")
    SourceLr = SourceSht.UsedRange.Rows.Count
    'create new sheet and set up headers:
    With Sheets.Add(After:=Sheets(Sheets.Count))
      SourceSht.Range("D1:D" & SourceLr).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range("A1"), Unique:=True
      NewShtLr = .UsedRange.Rows.Count
      .Range("A2:A" & NewShtLr).Copy
      .Range("B1").PasteSpecial Transpose:=True
      .Columns(1).ClearContents
      'populate columns in the new sheet:
      For Each cll In .Range("B1").Resize(, NewShtLr - 1).Cells
        SourceSht.Range("A1").AutoFilter Field:=4, Criteria1:=cll.Value
        SourceSht.Range("A2:A" & SourceLr).Copy cll.Offset(1)
      Next cll
    End With
    SourceSht.Range("B1").AutoFilter
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Aug 2012
    Posts
    24
    Location
    This worked incredibly! Thank you very much for your help!!

Tags for this Thread

Posting Permissions

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