+ Reply to Thread
Results 1 to 10 of 10

Using The Next Empty Column

  1. #1
    Registered User
    Join Date
    01-04-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Using The Next Empty Column

    Hello

    I'm a complete novice when it comes to Macro's. I'm trying to copy a cell of data (F564)and a column of data (K564:K639) from one sheet and copy them to a cell and a column in a second sheet (currently C1 and C5-C80), but want to use the first empty column in the second sheet each time, not Column C. This would be updated daily, with the most recent data being in the right-most column.

    I've been playing with offsets etc but cannot get it to work. Any help would be gratefully recieved!

    My current code is:

    Please Login or Register  to view this content.
    Many thanks,

    Stuart
    Last edited by Disco3Stu; 01-07-2011 at 04:46 AM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Using The Next Empty Column

    Hi Disco and welcome the best Excel forum on the net. You are violating forum rule #3 in that you need to wrap your code in code tags. Please read all of the forum rules and change your post accordingly. After you do that, someone will be more than happy to help you.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Using The Next Empty Column

    Hey Stuart, I have the answer but will get demerits if I tell you before you put code tags on.

    Click the Green "Edit" button below your original post and then select "Go Advanced" below the message area. Then select your code and click on the "#" icon above the message area. This will put code tags around your code. Save and that will do it.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    01-04-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Using The Next Empty Column

    Thanks Marvin. All tidied up....

    And rules read!
    Last edited by Disco3Stu; 01-04-2011 at 04:29 PM.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Using The Next Empty Column

    Cool,
    The problem is with your
    Please Login or Register  to view this content.
    Before you do
    Please Login or Register  to view this content.
    You are turning off the selection so nothing is copied into the Windows Clipboard.

    Remove that line and try again.

  6. #6
    Registered User
    Join Date
    01-04-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Using The Next Empty Column

    The copy/paste side of things is working ok, just the end location is wrong.

    As it stands, every time I run the macro the correct data is inserted into Sheet 2 Column C.

    What I would like to happen is the first time it is run the data goes to Column C, the next time Column D, then E, etc, always going into the next column.

  7. #7
    Registered User
    Join Date
    01-04-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Using The Next Empty Column

    A copy of the file....

    The macro is run from sheet 2 (Times).

    1st run should populate column C, 2nd run column D, etc.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-04-2011
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Using The Next Empty Column

    If you had a cell that is always populated with "paste data" for instance after pasting in column C cell 1 would always have something in it ect.. you could run a quick loop to determine the start value of your range.

    Please Login or Register  to view this content.
    You could then set your paste range to start at "cell 1,i" that would always be the first empty column and cell 1.

    Didn’t look into all your stuff just thought this might be a quick fix for you.

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Using The Next Empty Column

    Hi Stuart,

    Find the attached with a new/modified macro. You've found the problem with recording Macros and then playing them back. Things move around and you need new locations. I hope the code comments will make you think and learn.

    You need to almost memorize the lines of code below:
    Please Login or Register  to view this content.
    Also - your merged cells on the first sheet hurt you. The good Excel guys now almost never used merged cells. In the new code I don't think you need to unmerge cells as the new code only copies over a single cell.

    I hope you will see how to deal with more data.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    01-04-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Using The Next Empty Column

    Marvin, thank you so much

    The 'walk-through' is really great, I'd never have followed it otherwise. I'll spend some time looking through it today.

    Unfortunately I cannot get away from the merged cells as they are merged when the data is supplied to me. As you've already seen from the macro I've already realised what a pain they can be!



    Thank you for your time,


    Stuart


    PS:
    Quote Originally Posted by Mordred View Post
    and welcome the best Excel forum on the net.
    Looks like you were right!!
    Last edited by Disco3Stu; 01-07-2011 at 05:28 AM.

+ 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