+ Reply to Thread
Results 1 to 23 of 23

Copy cells relative to active cell

  1. #1
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Copy cells relative to active cell

    Hi Guys,

    I'm putting together a spreadsheet for a friend who runs a small business. He just wants it to keep track of jobs done and costs etc. As his keyboard skills are not great I'm trying to automate as much as possible. Many of the jobs he does are repeats of previous jobs and all the details are the same (Address, Contact, Hours, Materials, Equipment etc.) As each job is on a new row, I am trying to find a way of placing the cursor on an invoice number of the previous job and copying the relevant cells from that row. These details would then be pasted in the next blank row.

    ScreenSnapzExcelForum.gif

    I have (hopefully) added an image of what I hope will be the spreadsheet he needs. The macro buttons are at the top. So to copy the last job for 27 Everest St he would:

    • make the cell C3 active
    • Press the "Copy Job Details" button (this would copy cells D3:K3)
    • Select Cell C7
    • hit the "Paste Job Details" button (this would paste the copied values into D7:K7)

    If this could be done with one button it would be even better. Of course, he would have to replace the date unless there is a way to avoid copying that in the 1st place. I'd be happy to upload a copy of what I have to date if it helps but it is about 70Kb and I'm not sure of the rules/limits.

    Thanks to anyone who looks at this and even thinks of helping. :-)
    Attached Images Attached Images
    Last edited by Grouty; 12-20-2011 at 06:29 AM. Reason: Clearer image & clearer text.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    Uplaod the workbook, 70 kb is fine.
    In the mean time, if you can try this code to see if it is what you are after?
    I have named the worksheet "Sheet1", if your worksheet that has the data on it is named differently please tell me what it is?

    Please Login or Register  to view this content.
    Last edited by JapanDave; 12-18-2011 at 08:49 PM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Thanks for that,

    I'll try it as soon as I get to the laptop I'm doing it on. In the meantime, I meant to type 700Kb (not 70Kb) but I'll put it up anyway. (better to apologise than ask permission :-))
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    2 consecutive posts, isn't that considered bad form on some forums? Sorry about this. I was focussed on uploading the spreadsheet and didn't address the rest of your post.

    Anyway, as you may see if you look at the workbook, there will be more than one worksheet for which this needs to work. My friend has several agencies for which he does work as well as private clients. He wants a different sheet for each of these clients. So one client is 2nd Avenue Realty another is The Professionals Real Estate. Thus, I have named the sheets; 2nd Avenue, Professionals and will name others as they are added.

    Hope this helps. :-)

    Cheers,

    Grouty

  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    I imagine that you want a dynamic range for which the macro will automatically post in the next available row? The address columns have blank cells, will this always occur? And why don't you set it up so when a persons name is entered their address is automatically entered as well?

  6. #6
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Hi JapanDave

    In normal operation the rows will be completed consecutively. So. no blank rows. The names and addresses are not matched one for one. So, I set it up so that there are 2 validated lists (columns A and B) that contain the addresses and the names of the contact person. These would be completed by selecting from a drop down menu. My friend has many fine qualities but lacks basic keyboard skills and takes an age to type anything.

    For this reason I was even trying to get the date to enter automatically when there was something entered in column D. However, every way I tried it the date would change when the spreadsheet was opened again the following day.

    Many thanks for looking at this.

    Cheers,

    Grouty

  7. #7
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Deleted due to double post - browser crash! Sorry.

  8. #8
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    Could you elaborate a bit more on the date issue? And will the data always come from D3:K3?

  9. #9
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Steve, my friend with the small business, does gardening jobs and other handyman stuff. many of the lawns he cuts get done every 2-3 weeks and so all the details for the job are the same with the exception of the date. Thus, copying the necessary details from a line above would make sense and reduce the evil typing.

    As you can see from the workbook, the yellow columns are unprotected while the pink ones are protected. In truth, the cells to be copied and pasted from and to each row would ideally just be in columns: D, E, G, H, I, J, K and O. The more I look at this the more awkward it becomes. :-)

    Do you think this is do-able or have I set this up badly?

    As for the date, it would need to be changed from one instance of a job, on one row, to the next instance of that same job 2 or 3 weeks later on the next blank row. Even when a job is being entered manually it would be great if it would just appear automagically whenever an entry was being input in a row. The problem is that if I enter it as something simple like:
    Please Login or Register  to view this content.
    then when the workbook is opened on another date, all the dates change to the present date. Thus Steve has no record of what job was done when as all the dates are the present date.

    I tried a few bits of code I found on various web sites but they don't seem to have worked. My fault I'm sure but...

    As it stands I think I can train Steve to use the "ctrl-:" shortcut for date entering. It's not as elegant and it involves using the keyboard but anything else is beyond me at the moment.

    As I am writing down my wishes and desires I might as well add this: I'd like the cell containing the invoice number in the pasted row (in column C) to become selected after the pasting. This is because the button marked "Print Selected Invoice" pastes the entry in this cell for a VLOOKUP to be used in producing the invoice as a PDF. This would require Steve to select the right invoice in column C which he could probably do but no harm in asking?

    Thanks for all your time and effort on this so far. It is greatly appreciated.

    Cheers,

    Grant

  10. #10
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    The date issue should not be a problem, so Steve does not have to enter the date. And the last request is not a problem either. But looking at the data, the data in row 3 and row 5 are completely different?
    Or are asking that the data from the previous job for that client be pasted in the next available cell? And that would mean that there would not be any particular pattern as to when the next job would be?
    Last edited by JapanDave; 12-19-2011 at 02:11 AM.

  11. #11
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Quote Originally Posted by JapanDave View Post
    The date issue should not be a problem, so Steve does not have to enter the date. And the last request is not a problem either. But looking at the data, the data in row 3 and row 5 are completely different?
    Or are asking that the data from the previous job for that client be pasted in the next available cell? And that would mean that there would not be any particular pattern as to when the next job would be?
    I'm sorry, I didn't put enough thought into the data I was typing in to test stuff out. What is in the workbook I sent you is not very realistic. So, assuming that the job is a simple repeat with no extra items, I was thinking it might work like this:

    1. Steve mows the lawns at 27 Everest St again which is administered by 2nd Avenue Realty and for whom the contact person is Grant so he looks in the workbook and selects the 2nd Avenue sheet.
    2. He then looks back to find the last time he mowed at that house and selects the cell containing the invoice number for that occasion (cell C3 in this case).
    3. Next Steve hits the Copy Job Details button and the macro copies the relevant details and pastes them into the next empty row.
    4. The cell in column C of the row that was just pasted in is selected (ready for Steve to press the Print Selected Invoice button)

    There will be times when an exact copy would not be what was required. So Steve would mow the lawns at 27 Everest St but would also spray for pests or some other additional work requiring materials or equipment hire as well as additional hours. In this case he could copy as described above then add the extras - which is why the copy/paste macro shouldn't just print automatically.

    I hope this is clear. It all makes sense inside my head.

    Cheers,

    Grouty

  12. #12
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    I had already made up a Macro for you before I saw your last post. I wasn't sure why everything was the way it was so I just made a logical decision on what data needed to be copied.

    For the attached workbook I added 2 extra columns and when Steve chooses the company he did work for, it will look for the previous data on that company and copy the data into that row for that day. This automatically sets the date to today and if he wants to change that date he can. Or I can put it back the way you had it, as I am sure this will affect all the macros you have already made and have it run when the address of the company is selected.

    Select a company from the drop down in column E.

    Let me know if this was something you were looking for?
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Oh this is so close to what I need.

    Just a little misunderstanding. Each tab/worksheet is a company, the list of addresses on each sheet are properties the companies are hiring Steve to upkeep. Thus, the "Companies" column is redundant.

    Using it as it is though, I can see that it does so much of what I was trying to achieve. It does the copy and paste thing much better than I had hoped. I had thought it would have to be a 2 action thing rather than just a selection from a menu. Great!

    I notice a couple of cosmetic things that might be to do with different versions of Excel. The buttons I had for Show/Hide the "Customer Addresses" seem to have faded away - I can still see them and they still work but with no colour. Should be easy for me to fix.

    I tried using the "Print Selected Invoice" button and, as you predicted, it didn't work because of the extra columns. However, it also gave me a message that the workbook I was trying to paste to is using a different date system. I've seen this before but am confused as I am not trying to paste into a different workbook. I've obviously done something wrong as, this time, a different sheet actually opened. Not sure if you can help me with this too?

    As always, thanks for all the help.

    Cheers,

    Grouty

  14. #14
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    Ok, best leave the workbook as is then.

    We can use the the Address column to initiate the copy/paste process and this negates the need for adding columns. The workbook was the same as you described with the buttons when I opened it , I could hardly see them as well.

    I think the best thing would be to work out the code on this workbook you have now and when you have it the way you are after, just copy the VBA modules into the real workbook. Looking through the code you have a few unnecessary actions. Why do you always have the macro go back to C3? I would think if you are always going to print the last invoice made, you would want it to go to the last invoice on the list?

    As for the date issue, it could be due to the workbook I sent you is having issues with your OS's date. Again, to solve this, it is best that I give you the code and you put it in the workbook.

  15. #15
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    I'm pretty sure I have LOTS of unnecessary stuff in my code. Lots of trial and error. As for the one you spotted selecting cell C3, I had some code that copied whatever was selected and pasted it elsewhere. I stuffed things up royally a number of times by not having the correct cell selected when I ran the macro. I decided it was safer to know where the selection was. I discovered that Excel doesn't "undo" actions carried out by VBA code/macros.

    Thanks again.

    Cheers,

    Grant

  16. #16
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    Are all the sheets the same format for each company? If so, I have the code for you.

  17. #17
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    I just woke up. :-)

    I only really have the one sheet at present - 2nd Avenue. Once I have this sheet complete I'm planning to copy this sheet and change the invoice numbers to the pattern Steve uses at present. Thank you so much for all your help. I won't get to see anything until I return home tonight. Excited!

    Cheers,

    Grant
    Last edited by Grouty; 12-19-2011 at 07:25 PM. Reason: typo

  18. #18
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    Sorry, really busy day today.

    OK, the first bit of code needs to go in the worksheet.
    Right click the sheet tab name "2nd Avenue", paste the code in the window to the right.

    Please Login or Register  to view this content.
    The secodd bit of code needs to go into a standard module.
    Click the VB editor and insert a standard module and past the code into the window to the right.
    Please Login or Register  to view this content.
    And your done. Copy the 2nd Avenue sheet and rename it and the code will still work on the new sheet.

  19. #19
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Hi JapanDave

    You're going to think I'm a real dunce but I'm having trouble with the 1st part of this. If I right click the 2nd Avenue tab I see what is in this image:

    ScreenSnapzRtClick.gif

    I don't see any "window to the right". I'm sorry. Might this be a Windows vs Mac thing?

  20. #20
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    OK, lets do this a different way.
    You are on 2010 so this should work.

    Click "View" in the ribbon on top of the worksheet>Very far right,click view macro>Click edit on the righ hand side of the popup window>You are now in VB editor>Click on View> Click project explorer>You should now have something similar to the attachment > double click the sheet names 2nd avenue> when the window to the right appears> paste first bit of code.

    http://www.wordstream.com/images/screenshots/pt5_1.png

  21. #21
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Absolutely brilliant. It works perfectly!

    I'm sorry for being a bit slow. I didn't realise you just needed me to insert the 1st bit of code into the worksheet in the VBA editor. I thought you meant the Workbook/worksheet. Duh! Couldn't see how that was possible but it didn't stop me trying.

    I did it all as you described and it does exactly what I need. I'm looking forward to getting the rest of it done now and giving it to Steve. Might even make it his Christmas present.

    Thanks again for all the effort you put into this. I think I'll go get a VBA book and try and work out what all the code means.

    Have a great Christmas and a happy New Year.

    Cheers,

    Grouty

    PS if you know of any good VBA primers let me know.

  22. #22
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Copy cells relative to active cell

    Great to hear it works. You will need to edit your original post the solved and if you liked the answer , don't be afraid to click the little star at the bottom hand corner and give some rep points.

    Cheers, and have a safe Christmas and New Year.

  23. #23
    Registered User
    Join Date
    12-10-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Office 365 Subscription
    Posts
    26

    Re: Copy cells relative to active cell

    Hi again JapanDave,

    I have changed the title to include [SOLVED] and I did the little star thing yesterday. I tried again today but it won't let me do it again until I do so for someone else. Shame as I think you deserve it.

+ 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