+ Reply to Thread
Results 1 to 8 of 8

VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

  1. #1
    Registered User
    Join Date
    02-18-2019
    Location
    Texas
    MS-Off Ver
    Office 365
    Posts
    8

    Lightbulb VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

    Okay, I am new to vba and this will be my first project. I have been watching a few videos on YT, but this is still a little confusing to me. I hope someone can assist or give me steps to understand what is needed to be done to accomplish what I need. The only rows that are important are the following “part” numbers. (1, 7 and 71).
    • In the column named “Part” I need to search for the number “1” and pull the data in the “Key” Column and paste it to column “1” all the way down until its sees another “1” in column “Part”. If the column has a “0” in it skip it.
    • Next I need to search for “Part” no 71 that is between the current “Part” 1” but above the next “Part 1” it locates and copy the data from the “key” column and paste it to column “2” on the rows that match the last digit to column “ID”.
    • The last row will always end with a 7 also.
    I will attach a finished example of what I am trying to do. This code will run against thousands of rows daily of this same workbook. I hope I didn’t confuse anyone too much.

    Many thanks in advance for anyone that can help.

    Jgarza0422
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

    Hi Jgarza and welcome to the forum,

    I think you are needing something called Fill Down located in the Power Query tool inside Excel. My scheme it to do this.

    If column C has a 1 in it you would copy the value in column I over to Column A. If Column C has a 71 you would copy the value in Column I to Column B. Now using Power Query you would simply fill down all the values in Column A and B.

    https://www.excelcampus.com/library/...s-power-query/

    Time to get/learn Power Query?

    Marv Parsons
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    02-18-2019
    Location
    Texas
    MS-Off Ver
    Office 365
    Posts
    8

    Re: VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

    MarvinP, thanks for the warm welcome. I think left out a piece of information. This report file gets generated daily ad the data I have to fill in would be done daily also, as this is why I wanted a programmatically way of getting the results I needed. I did review about the Power Query, but this will only be helpful if I had to perform this action once. But thanks for the suggestion. Do you think this is still possible with VBA or is there another way you can suggest?

    Jgarza0422

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

    Hi jgarza,

    Power Query allows you to program some steps and then simply point to a different file and it would do the work. Can you attach a sample file an I'll do what I suggested above and give it back to see if it is what you want. It will take about 3 minutes to do the whole process. After that you can simply point to a new "Source" file and it will be done again.

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  5. #5
    Registered User
    Join Date
    02-18-2019
    Location
    Texas
    MS-Off Ver
    Office 365
    Posts
    8

    Re: VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

    The file are attached to my original post. Thanks.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

    Ok,

    Took about 2 minutes to convert your data to sheet2. I used the Power Query statements below.

    Please Login or Register  to view this content.
    I think you wanted column B to be repeated on 7 instead of 71? I did 71. I never needed to type a formula in doing the above. It was easy peasy!!! Time to learn Power Query?

    Marv

    Repeat-Raw Data Answer.xlsx

  7. #7
    Registered User
    Join Date
    02-18-2019
    Location
    Texas
    MS-Off Ver
    Office 365
    Posts
    8

    Re: VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

    Thanks I will review tomorrow at work. Greatly appreciated. I just learned about Power Query. Thanks for the insight.

  8. #8
    Registered User
    Join Date
    02-18-2019
    Location
    Texas
    MS-Off Ver
    Office 365
    Posts
    8

    Re: VBA Code to Copy Data From Last Row Based on A Value and Past into Blank Column

    MarvinP, Thanks for showing me this amazing tool. I managed to recreate the file using yours as a guide and I managed to pick up pretty quick. So again, thanks for the direction. Now I need to learn more about this tool.

    Jgarza0422

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy-past of a row from a sheet to another, based on the value in the first column.
    By marcomajo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2018, 11:32 AM
  2. VBA code to copy and past rows of data
    By tompee29 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-12-2018, 11:37 AM
  3. [SOLVED] copy rows out of a datasheet based on a code number and past these rows in a new sheet
    By Robert1311 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-11-2018, 11:41 AM
  4. Copy value of one cell and past in new column only where data exists
    By MikeWaring in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-24-2017, 11:00 AM
  5. vba code to be able to past into the next specified range in the next blank row
    By markswan111 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-27-2016, 10:23 AM
  6. Copy the values from A column and past into new work book based on condition
    By akmughal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2015, 03:43 PM
  7. Linking data based on a cell value and copy/past to another worksheet??
    By Tweech in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2012, 01:12 PM

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