+ Reply to Thread
Results 1 to 14 of 14

Copy Data Range Between Blank Cells in Column

  1. #1
    Registered User
    Join Date
    12-16-2011
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    7

    Copy Data Range Between Blank Cells in Column

    So I've got a seemingly simple problem that I haven't been able to figure out.

    In column A, I have dates. Column B has a job type. Column C has payment. Here's a sample workbook to show what I mean
    Sample.xlsm

    Now, what I want to do has two parts:
    First I want to find the first instance of Job "1" (B1), then count down until it reaches Job "2" (B6).
    The second part is to copy all the cells from A1 to C5 (All of the Job 1s on 12/1). Then paste that data into the sheet "Job1".
    Then continue and find the next instance of job "1" in column B and count down until it reaches the next job type, etc.

    Now, I can figure out how to get the second part to work. I'm having trouble with the first - counting the cells between Job "1" and "2" in order to copy only the data pertaining to job "1"

    I realize this would be easy if I just filled B2:B5 with job "1", but my boss likes the current layout.

    Thanks

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Copy Data Range Between Blank Cells in Column

    Does your actual workbook have headers in row 1 (or elsewhere, as opposed to no headers at all)?
    Does your actual workbook already have sheets named 'Job1', 'Job2', etc or do those need to be created?
    Is the worksheet naming scheme 'Job1', 'Job2', etc accurate?
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    12-16-2011
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Data Range Between Blank Cells in Column

    Quote Originally Posted by tigeravatar View Post
    Does your actual workbook have headers in row 1 (or elsewhere, as opposed to no headers at all)?
    Does your actual workbook already have sheets named 'Job1', 'Job2', etc or do those need to be created?
    Is the worksheet naming scheme 'Job1', 'Job2', etc accurate?
    Yes, there are headers. Let's say they're Date (A1), Job (B1), and Pay (C1).

    The sheets already exist, and no the naming scheme isn't accurate (there's actually a lot more information involved, but I'm simplifying things).

    Really what I need is that first part - counting the blank cells between Job 1 and 2 so that I can copy and paste the range (which I believe I can manage myself).

    Thanks

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Copy Data Range Between Blank Cells in Column

    rs235251,

    Alright, this should get you started then:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by tigeravatar; 12-16-2011 at 02:10 PM.

  5. #5
    Registered User
    Join Date
    12-16-2011
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Data Range Between Blank Cells in Column

    Quote Originally Posted by tigeravatar View Post
    rs235251,

    Alright, this should get you started then:
    Thanks, that works brilliantly in that example.

    I'm having a little trouble getting it to work with my workbook though. I didn't expect this to be a problem, but the cells in column B aren't actually called 1,2,3. They have text-based names. The sheets they're being copied to are named the same, still. I've tried tweaking the
    Please Login or Register  to view this content.
    part of the macro you wrote and I'm getting a bunch of different errors with everything I attempt.

    Sorry for the confusion. What you wrote is largely out of my VBA skill level.

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Copy Data Range Between Blank Cells in Column

    What is the naming convention? If you have jobs xxx, yyy, and zzz, are the sheets named 'Jobxxx', 'Jobyyy', 'Jobzzz'? or something different? (like 'Work Order xxx', etc)

  7. #7
    Registered User
    Join Date
    12-16-2011
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Data Range Between Blank Cells in Column

    There is no naming convention. It's just xxx, yyy, zzz. All unrelated in name.

    Really appreciate the help

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Copy Data Range Between Blank Cells in Column

    If that's the case, give this a try:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-16-2011
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Data Range Between Blank Cells in Column

    Quote Originally Posted by tigeravatar View Post
    If that's the case, give this a try:
    Please Login or Register  to view this content.
    That's great, working really well.

    Only one problem though - when it copies over the most recent job in the master log, it copies everything blank below it. So it's copying down to row 1048576.

    You may have a better idea, but I think an if/then statement might work where if it found more than, say, 30 blanks after the last job then it would stop?

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Copy Data Range Between Blank Cells in Column

    This line was the once causing the problem, due to the .End(xlDown). It was just going to the bottom if there was no data underneath it:
    Please Login or Register  to view this content.


    Replaced that line with this line which goes to the last row in column C:
    Please Login or Register  to view this content.


    Here's the full code, with the above adjustment and the worksheet name adjustment from earlier:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-16-2011
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Data Range Between Blank Cells in Column

    That's amazing. You're fantastic

  12. #12
    Registered User
    Join Date
    12-16-2011
    Location
    N/A
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Data Range Between Blank Cells in Column

    Ok, new day and a followup question...

    If I wanted to copy all the entries for jobs 2 & 3 into Sheet5, but not job 1, how would I do that?

    I was trying out various tweaks reusing this bit of code from above:
    Please Login or Register  to view this content.
    ...using an if/then statement to delete job 1 as a criteria in arrUnq. It worked - but when it copied over to Sheet5 it was sorted by job and I wanted it to be sorted by date and then job. Didn't manage to get that part to work, and subsequent attempted tweaks have broken the copying over at all..

    Thanks

  13. #13
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Copy Data Range Between Blank Cells in Column

    rs235251,

    You need to change the autofilter line to filter all items that you don't want, the rest of the code should be left alone.
    To filter multiple items, you need to tell it the array to filter and then you need to specify to filter on values.
    In the original code, its filter "=", which means its filtering out blanks so that it goes through unique, non-blank items.
    In the example workbook, Job 1 is just "1", so the line would be:
    Please Login or Register  to view this content.


    Here's what it looks like with that snippet you posted:
    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,583

    Re: Copy Data Range Between Blank Cells in Column

    Pl see the code below. It may help .

    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)

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