+ Reply to Thread
Results 1 to 6 of 6

Macro to copy paste values if cell is not empty

  1. #1
    Registered User
    Join Date
    09-29-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    40

    Macro to copy paste values if cell is not empty

    Hi everybody,

    I need your help today for a quite basic procedure (I think) on VBA. The only problem is that I don't know any VBA so I thought about asking for your kind help for the basic functions that might be useful.

    I have 2 spreadsheets A and B.

    The thing I want to do is go through a column (called correction in my example) and check if the cell is empty or not on spreadsheet B.

    If that cell is empty, then we move to the next cell which is one row below on the same column.

    If that cell is not empty, then I would like to memorize the value of all three columns (called WBS, meaning and correction) and put them on the first spreadsheet A in an array.

    I would like to do this for all cells within Column Correction.

    If somebody could help me with the functions, I know how to do all of them in excel and I do understand the basics of while, if and for loops but I have a hard time finding the good syntax as everything I write ends up bugging ...


    Thank you so much!

    Xenthys
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to copy paste values if cell is not empty

    Hello Freind

    The first thing to learn about VBA is that we never use Loops unless absolutely necessary.

    The second thing to learn is that we never loop through each cell in a data set unless absolutely necessary.

    In your example:

    Select all the data with text in column "E", Use the Excel Function: Goto Special.

    Add Row 6 to your selection

    Copy that data and paste to Sheet 1.

    I will be a couple of minutes writing the code:-
    Last edited by mehmetcik; 10-15-2017 at 03:24 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    09-29-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    40

    Re: Macro to copy paste values if cell is not empty

    Thank you so much for your answer.

    I do understand what you mean even though it seemed more intuitive for me to do something like:
    For i= first row not empty until last row not empty
    screen each cell and when it is not empty copy paste the 3 values on the other spreadsheet
    otherwise move to the next one.


    This because my dataset is full of "holes" and I may very well have only 3 values on that column correction in about 500 rows, separated by dozens of rows ...

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to copy paste values if cell is not empty

    I cannot post my code.

    Look at the attachment. Click on the button on the sheet "Example"

    I agree that your way is the intuitive way to do this but it will be very slow.

    For the few lines that you have in your example who cares.

    But with any serious amount of data you will notice a severe lag.
    Attached Files Attached Files
    Last edited by mehmetcik; 10-15-2017 at 03:21 PM.

  5. #5
    Registered User
    Join Date
    09-29-2017
    Location
    London
    MS-Off Ver
    2010
    Posts
    40

    Re: Macro to copy paste values if cell is not empty

    That is incredible, I am amazed at how you could do this so quickly when I honestly spent almost half a day doing something that doesn't work. Well, thank you again, I wil go through all your code very thoroughly and ask for help about any function if I haven't understood something.

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Macro to copy paste values if cell is not empty

    You can use Autofilter to search for none-blank cells, then copy the range to the other sheet,



    Please Login or Register  to view this content.

+ 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. Paste Values empty cell, not empty
    By warston in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 12-23-2020, 08:16 PM
  2. [SOLVED] Need macro to copy paste in empty cell.
    By Revathi kannan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-20-2016, 06:22 AM
  3. Macro to copy and paste data to next empty cell.
    By Shellybelly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2015, 10:41 AM
  4. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM
  5. Copy values from cell in active row, paste in first empty cell in spesified column.
    By Test123Test in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2012, 05:20 PM
  6. Macro to copy and paste to an empty cell
    By arodiaz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-06-2011, 07:08 AM
  7. Macro-Copy&Paste Fixed Data Ranges Into Last Empty Cell of Specific Column
    By hailnorm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2009, 10:15 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