+ Reply to Thread
Results 1 to 21 of 21

Copy certain range when a cell is not blank

  1. #1
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Question Copy certain range when a cell is not blank

    Hi, all

    I have this data where it shows the parameters with unit as well as the monthly data and average. My issue is I would like to copy paste column "parameters", "unit" and "average", only if "average" has some values. The copied data will be pasted in the same sheet. May I know how to start? I have tried to search for a solution but it's still a bit blurry to me.

    Hereby I attached an Excel file that almost matches to my actual file. Your help will be really appreciated. Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    Give this a go...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Hi, Sintek

    Thank you so much for this! I'm currently altering this code to suit my actual file hence, can I know what is meant by SpecialCells (12)? What is meant by 12?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Copy certain range when a cell is not blank

    ell_
    Your sheet layout is just made for AdvancedFilter.
    Please Login or Register  to view this content.
    P.S.
    You need to delete extra space at the end in P1 "Avg " to match with T3 "Avg".
    Last edited by jindon; 01-10-2018 at 04:35 AM.

  5. #5
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Hi, Jindon

    I got an error - Application-defined or object-defined error, may I know why?

    P/s: I have deleted the extra space

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Copy certain range when a cell is not blank

    Named range plays funny sometimes.
    Try this one then
    Please Login or Register  to view this content.

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    what is meant by SpecialCells (12)
    visible cells after filter

  8. #8
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Hi, Sintek

    Currently trying your code but it doesn't work as what I expected when I played with it. Here's my code:

    Please Login or Register  to view this content.
    The blank data in column AI are still copied to AL33. May I know why?

    Capture.PNG

    To Jindon, thank you so much for this! I might be able to use it to my other sheets.
    Last edited by ell_; 01-10-2018 at 09:01 PM.

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    Please Login or Register  to view this content.
    The 16 above is for column P, You are now using Column AI which is Col # 35

    Upload a sample of your new setup...
    Last edited by sintek; 01-11-2018 at 01:40 AM.

  10. #10
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Hi, Sintek

    I have changed 16 to 35 but the same thing happens. Is it probably due to the reason that my data starts at row 9?

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    Upload a sample...Can't say until I see...

  12. #12
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Sintek,

    Here is the edited Excel file which is similar to the actual file. The top rows (1-8) have some other data which will be ignored in this case. Thank you so much!

    P/s: I'm also hiding the columns in between because I only want to see column B, C and AI in the actual file
    Attached Files Attached Files

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    The top rows (1-8) have some other data
    Quite important to know which columns this data occupies...Otherwise this snippet of code won't work
    Please Login or Register  to view this content.
    Edit....
    Not to worry...This workaround...
    Please Login or Register  to view this content.
    Last edited by sintek; 01-11-2018 at 02:09 AM.

  14. #14
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Hi Sintek,

    Here's the updated Excel. In actual file, the parameters will increase or decrease, number of rows occupied will change from time to time. But the summarized table in AL33 will not change its position. Hope that clarifies. Thanks!
    Attached Files Attached Files

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    Do you now see how important actual worksheet setup is in order for us to assist...All 3 your uploads are different and hence the code has to be adapted to suite...
    Please Login or Register  to view this content.
    Last edited by sintek; 01-11-2018 at 02:32 AM.

  16. #16
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Thank you, Sintek! And my apology for the trouble.

    May I know if this code be capable of filtering up to 50++ rows? Just in case if the data increases in the future.

  17. #17
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    Yep, filtering is always better than looping...See change in code Post #15 - red part - to speed up.

  18. #18
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Thank you so much, Sintek! And sorry again for the trouble :/

    Works like a charm.

    Another curiosity is, what if I want to apply this code to do the same thing, but pasting it to different sheet? And in this case, I want to copy all the columns from B to AI?

    I know I should change:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Right?

  19. #19
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    Please Login or Register  to view this content.
    Copy code remains the same...

  20. #20
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy certain range when a cell is not blank

    Thank you so much, Sintek!

    Definitely a life saver.

  21. #21
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: Copy certain range when a cell is not blank

    Glad I could help. Thanks for rep +

+ 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. [SOLVED] Vba code to copy into first blank cell within a range
    By A440 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-26-2017, 03:56 PM
  2. [SOLVED] VBA to copy a1 to the next blank cell in a range U18:U23
    By A440 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-15-2016, 02:59 PM
  3. VBA macro to copy last non blank cell on a certain range that has formula
    By danwoltrs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2016, 03:58 PM
  4. [SOLVED] Copy Cell Adjacent to Blank Cell in Range.
    By NewExcelUser in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-20-2015, 07:45 PM
  5. [SOLVED] Copy / Paste range from one sheet to another, if cell in column A is not blank
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2014, 09:18 AM
  6. macro to copy changing range to next blank cell in another sheet
    By d2whales in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-09-2013, 12:55 PM
  7. [SOLVED] Copy data from a range of cells into a blank range based on common cell
    By vanmeterkj in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-03-2012, 10:18 AM

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