+ Reply to Thread
Results 1 to 6 of 6

macro to copy changing range to next blank cell in another sheet

  1. #1
    Registered User
    Join Date
    07-03-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2010
    Posts
    4

    macro to copy changing range to next blank cell in another sheet

    Hi-

    I'm building part of a macro in which I want to copy and paste a filtered range (whose size changes with each run) to the next blank cell after cell A24 in another worksheet. The next blank cell is always changing.

    I'm an Excel novice compared to most of you and record most of my macros. I have a rudimentary understanding of VBA and need something simple. I'm hoping to find a way to use END+DOWN in the macro but don't know how to indicate "wherever" the next blank cell in the column is after cell A24.

    Any help is much appreciated!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: macro to copy changing range to next blank cell in another sheet

    Hi

    Assuming that underneath the next blank cell after A24 there are no other cells with data then the usual way is to use

    Please Login or Register  to view this content.
    And as an aside re copying your filtered range, don't forget you can always use code like

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    But better still use a dynamic range name that results in a single column. e.g
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-03-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: macro to copy changing range to next blank cell in another sheet

    Hi Richard,

    This is what I was afraid of--looking like an idiot. I don't know what that means.

    Can you tell me what this code actually means in English: Range("A" & Rows.Count).End(xlUp).Cells(2,1)?

    You are correct in assuming there would be no data below the next blank cell after A24. Here is the little part of the macro I'm working on. When I run it like this, I get a Syntax Error.

    Range("A19").Select
    Selection.CurrentRegion.Select
    Selection.Copy
    Sheets("ADULT FICTION").Select
    Range("A" & Rows.Count).End(xlUp).Cells(2,1)
    ActiveSheet.Paste
    Range("A24").Select
    Sheets("ADULT SORT").Select
    Application.CutCopyMode = False

    Thanks, Richard!

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: macro to copy changing range to next blank cell in another sheet

    Hi,

    Try the following if your data is all values rather than formulae.
    Please Login or Register  to view this content.
    If the data are formulae and you want values then
    Please Login or Register  to view this content.

    I had originally thought that since you mentioned the next blank cell that you perhaps wanted to copy that blank cell too. Hence the reference to .Cells(2,1). I suspect that you only want to copy down to the last value in the range so the above does not need the .Cells(2,1) reference.

    In the original formula the
    Range("A" & Rows.Count)
    evaluates to
    Range("A1048576")
    since there are 1048576 rows on Excel 2007/2010
    The .End(xlUp) simply moves upwards from row 1048576 until it finds the next non blank value.
    The .Cells(2,1) then just identifies a cell which is the second row and first column away from the reference cell. So for instance if the .End(xlUp) were to find cell A45, then adding .Cells(2,1) to the instruction will position you at A46. A .Cells(4,3) would position you at C49.

    However why don't you upload your workbook and explain your ultimate goal. The fact that you have a sheet named Sort makes me think you may be able to achieve your aim without necessarily copying data elsewhere. It's often the case that people ignore Excel's ability to Filter or sort data in place.
    Last edited by Richard Buttrey; 07-04-2013 at 04:56 AM.

  5. #5
    Registered User
    Join Date
    07-03-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: macro to copy changing range to next blank cell in another sheet

    Hi,

    Attaching: copy of sheets in question (copied to Excel '03 because I'm not on my own computer at the moment). The macro you've been helping me with is 6E.

    Cell A19 in sheet Adult Sort is the beginning of filtered and sorted data I want to move to sheet Adult Fiction, starting in the first blank cell after cell A24. Cells A1-A23 are reserved for further filters if needed later in the process. There are about 7 other groups of data that will be filtered and sorted in sheet Adult Sort before being copied to their places in line in sheet Adult Fiction. I am only copying values, no formulae. The filter and sort for each group takes place in sheet Adult Sort.

    In the real workbook, there are 10 worksheets and 6 "official" macros. For each step in the process I'm building a macro to perform a small function. Once that's working, I move on to the next function and a new macro. When I'm finished and each piece is working, I'll combine all the macros into one.

    What does the following expression mean in English? Destination:=Sheets("Adult Fiction").Range("A24") I understand that the destination for the copy is in sheet Adult Fiction but the .Range("A24") sounds like it will actually paste in cell A24 instead of the first blank cell after cell A24.

    I seem to be having trouble with the Paste now. I've tried ActivateCell.Paste and ActiveSheet.Paste but I really have no idea how to activate the first blank cell after cell A24 for the Paste.

    I so appreciate your time and patience.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-03-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: macro to copy changing range to next blank cell in another sheet

    Bump No Response

+ 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