+ Reply to Thread
Results 1 to 12 of 12

Copy all cells except blanks, keeping the same spacing.

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Cool Copy all cells except blanks, keeping the same spacing.

    Hi guys,

    I've looked around the web and cant find a solution to my problem.
    What I want is similar to copy and paste, except it doesn't copy over existing cells in the final range.

    I'll provide an example:
    the following cells are
    A1 = stringA
    A2 = empty
    A3 = stringB

    B1 = 4
    B2 = B1*B3
    B3 = 5

    resulting in:
    B1 = stringA
    B2 = B1*B3
    B3 = stringB


    Ideally I would want this to work for any sized range (rangeA and range B always the same column and row dimensions however of any size), and copying from any part of the sheet to another.

    Any help would be great,
    Thanks.
    Jimmy
    Last edited by JimmyWilliams; 10-25-2017 at 07:13 PM. Reason: Made a mistake

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy all cells except blanks, keeping the same spacing.

    So what is the rule - I do not get it from your example
    A1 string, B1 number - required result = string from A
    A3 string, B3 number - required result = number from B
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Copy all cells except blanks, keeping the same spacing.

    Quote Originally Posted by kev_ View Post
    So what is the rule - I do not get it from your example
    A1 string, B1 number - required result = string from A
    A3 string, B3 number - required result = number from B

    Hi Kev_,
    it doesn't matter what A1,A2 or A3 are, the only thing that matters if making sure that they have not blank cells/empty.

    the result is exactly the same as normally Copying and pasting from A1 to A3 into B1 to B3, except that because A2 is empty, that cell isn't copied onto B2.

    Thanks for the message, sorry I wasn't clear enough. hope that helps.

    Jimmy

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy all cells except blanks, keeping the same spacing.

    Going back to post#1

    A1 = stringA, Not blank, copied to B1, and B1 = stringA
    Following same logic
    A3 = stringB, Not blank, so B3 = stringB

    But - post#1 says B3 result = 5
    Why?

  5. #5
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Copy all cells except blanks, keeping the same spacing.

    Quote Originally Posted by kev_ View Post
    Going back to post#1

    A1 = stringA, Not blank, copied to B1, and B1 = stringA
    Following same logic
    A3 = stringB, Not blank, so B3 = stringB

    But - post#1 says B3 result = 5
    Why?
    Think I make a mistake, fixed my original post!

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy all cells except blanks, keeping the same spacing.

    Will the range selected always be a single column?

    If not, if range S10 to W23 is selected, where do the values go?

  7. #7
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Copy all cells except blanks, keeping the same spacing.

    S10 to W23 is a range of 5 rows and 14 columns.
    After the copy step, the macro would give you a chance to select the cell to "paste" to.
    If you picked O1, the "pasted" range would be O1 to S14 (5 rows to the right, 14 columns down).
    Non-blank values found within the S10-W23 would copy over existing values in O1-S14.
    Say
    S11 = blank, T11 = 5
    O2 = 4, P2 = 2
    the result would be
    O2 = 4, P2 = 5

    Thanks Kev_!

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

    Re: Copy all cells except blanks, keeping the same spacing.

    You should use a formula in an empty column.

    Paste this formula in cell C1 and fill down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Copy Column C and Paste Special values into cell B1.

    Select Column B.

    Select the Data Tab, Select Text to Columns and click on finish.

    Job Done.

    As a Macro:-

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 10-25-2017 at 09:57 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.

  9. #9
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Copy all cells except blanks, keeping the same spacing.

    If it was just one column and you want it in the right click menu (the point of the first section) this is a start
    (note I am creating the reference that you may or may not have)

    in the thisworkbook module

    Please Login or Register  to view this content.
    and this in the normal module

    Please Login or Register  to view this content.
    Ahh i see your answer was that it was a range in that case i'd need to split by vbtab as well... not sure the efficient way to do that.
    Last edited by scottiex; 10-25-2017 at 10:33 PM. Reason: woops slight misreading of instructions
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  10. #10
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Copy all cells except blanks, keeping the same spacing.

    Hey all, thanks for the messages, will review when I can and get back to you all.

    Thanks,
    Jimmy

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy all cells except blanks, keeping the same spacing.

    deleted by kev - see post#12
    Last edited by kev_; 10-26-2017 at 01:01 AM.

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Copy all cells except blanks, keeping the same spacing.

    Select cells to copy and run a macro
    Test in attached workbook with shortcut

    This is the normal copy and paste - cell references are re-referenced: shortcut {CTRL} k
    Please Login or Register  to view this content.
    This literally copies whatever is in each cell - cell references do not change: shortcut {CTRL} {SHIFT} k
    Please Login or Register  to view this content.
    This pastes values: shortcut {CTRL} {SHIFT} v
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kev_; 10-26-2017 at 12:52 AM.

+ 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] Keeping a formula pattern to copy to cells below
    By craynerd in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-02-2017, 09:55 AM
  2. Copy cells to a new sheet spacing out the destination cells
    By brianrhoff in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-06-2014, 01:07 PM
  3. Replies: 1
    Last Post: 10-13-2013, 04:01 PM
  4. Replies: 1
    Last Post: 10-24-2012, 01:21 PM
  5. Replies: 2
    Last Post: 06-07-2010, 09:23 PM
  6. Replies: 2
    Last Post: 07-07-2008, 12:05 PM
  7. [SOLVED] How to copy cells with keeping exact formula intact
    By Stephen in forum Excel General
    Replies: 6
    Last Post: 04-03-2005, 06:06 PM

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