+ Reply to Thread
Results 1 to 4 of 4

VB Code to Copy & Paste based on Excel Column Value?

Hybrid View

  1. #1
    Registered User
    Join Date
    04-12-2012
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    4

    VB Code to Copy & Paste based on Excel Column Value?

    Hello,
    I am needing help with creating a macro to sort a document downloaded from PeopleSoft each morning (read only), and placed into an excel template document based on a column's value. I have attached an example excel document ("MacroHelp.xlsm") with data I am needing to extract.

    As you can see in column E ("Method"), there will be either 'ACH' or CHK'.

    If column E shows 'ACH', I would like to copy all of the data (Column A through Column G) and place it into a different document already created (see attachment 'T&E - ACH Template.xls').

    If column E shows 'CHK', I would like to copy all of the data (Column A through Column G) and place it into a different document already created (see attachment 'T&E - Check Template.xls').

    These templates are reused everday. Meaning, once these templates are filled in correctly with their data, I print and close without saving.

    Thanks in advance for any help you can offer!
    Attached Files Attached Files

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: VB Code to Copy & Paste based on Excel Column Value?

    Heres an example. All 3 workboks must be in the same folder. Download and put all three workbooks into the same folder.

    MacroHelp v1.xlsm
    Last edited by mike7952; 10-10-2012 at 02:38 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    04-12-2012
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VB Code to Copy & Paste based on Excel Column Value?

    Mike,
    That worked beautifully - many thanks!

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VB Code to Copy & Paste based on Excel Column Value?

    Hi MissMeliss,

    You may have to tweak the Source Book Name:

    Sub DisperseData(): Dim i As Long, j As Long, k As Long
    Dim wd As Worksheet, wc As Worksheet, wa As Worksheet
    Set wd = Workbooks("Macro Help").Worksheets("Sheet1")
    Set wc = Workbooks("T & E - Check Template.xls").Worksheets("Sheet1")
    Set wa = Workbooks("T & E - ACH Template.xls").Worksheets("Sheet1")
    For i = 3 To wd.Range("E" & Rows.count).End(xlUp).row
    If wd.Range("E" & i) = "CHK" Then
    j = wc.Range("E" & Rows.count).End(xlUp).row + 1
    wd.Range("A" & i & ":G" & i).Copy wc.Range("B" & j)
    ElseIf wd.Range("E" & i) = "ACH" Then
    k = wa.Range("E" & Rows.count).End(xlUp).row + 1
    wd.Range("A" & i & ":G" & i).Copy wa.Range("B" & k)
    End If: Next i: End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.6.0 RC 1