+ Reply to Thread
Results 1 to 20 of 20

Vba Paste Offset

  1. #1
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Vba Paste Offset

    Hello all,

    I am a vba noob, so excuse me but I am stuck:

    My goal is to
    1. copy a single cell value from a certain row (8), (want to do this for many columns, until value is null in that row)

    Please Login or Register  to view this content.
    2. paste it into a particular cell on another sheet. (this location will stay constant)

    Please Login or Register  to view this content.
    3. Then copy the output range of that input and paste it back into the original sheet. (the paste location will be within the same column and the first value originally copied)
    Please Login or Register  to view this content.
    4. then i want to go to the next column, pull that value from row 8 and paste it into the same input cell on the other sheet, while posting the new range output within the same column. I have tried multiple loop types and the best I've got is it will just get stuck in a loop. I guess this is an "offset" problem. Can anyone clarify? Am I making sense?

    Thanks in advance!
    Last edited by Cutter; 07-19-2012 at 08:34 PM. Reason: Added code tags

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Vba Paste Offset

    #1 + #2:
    Please Login or Register  to view this content.
    Don't understand 3,4. You should post a sample workbook.
    Last edited by Cutter; 07-20-2012 at 11:47 AM. Reason: Added code tags
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    Sorry, somehow I knew I wasn't clear enough. Please refer to the attached sheet, I can't send the real one but it shoudl get my point across.

    So I am looking to pull the values on row 6 (orange) and one by one paste them into 'input cell' (yellow).
    then, take the output range (purple) and paste it in to the corresponding column (blue).

    Whetehr its a while or do until loop, I'd like it to stop when it hits a null value on the orange row 6.

    Thanks!
    Mike
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    Try this:

    In Sheet2(Staffing):
    Please Login or Register  to view this content.
    In Module1:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    Hi,

    Sorry but I think again i was not clear enough.

    I want to paste the output range to the staffing sheet for each individual input in each column. step by step:

    row 6 orange values updated manually.
    button click
    first value in row 6 is pasted into input cell.
    output range (input sheet) updates
    output range is copied/pasted to staffing sheet directly underneath the corresponding row 6 value.
    then, next row 6 value is pasted to input, processed, and output range it returned directly underneath in the same column, on the staffing sheet.



    Am I making sense? I think my colors were misleading in the fact that they were not in the same column.

    Thanks!

  6. #6
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    Ok I think I understand now. So you would prefer using a button to update the values in the blue columns once all values in row 6 have been inputted rather than have the blue columns auto update when the values in row 6 are changed?

  7. #7
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    Yes exactly. I will likely be pasting in a new row of data all at once and then have a button to update it. But yes, for a given input in row 6, the corresponding output range needs to populate directly underneath.

    The actual formula for hte output range is based on a bunch of conditional statements, etc, so I'm not able to use a formula in a loop and apply it to all rows. Thanks!

  8. #8
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    Ok so I may be missing something because I don't see your full workbook, but why cant you just have your formula in the purple column on the input sheet in each blue column beneath the row 6 value?

  9. #9
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    No that would make a lot of sense. What I was trying to explain is that the equation covers multiple columns and is based on a few conditional statements, and I don't have any idea how I would consolidate it into one column/cell. There are about 4 other assumptions made and about 5 columns of computation before the output range is made.

    Thanks!
    MIke

  10. #10
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    Could you possibly upload a more detailed version of your document? I am not sure if this would apply to this but possibly use the concatenate function to merge multiple cell values into one cell? Otherwise I will try the button for you.

  11. #11
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    Hi, sorry for taking so long. Here is an excerpt from my workbook to show exactly what I want.

    I want to be able to paste/update in values in the yellow row of staffing. Then, with a button click send each yellow row value to the input sheet and paste it into the orange cell. Then, copy the green RESULT column from the input sheet, and paste it into the green column in the staffing sheet directly under the corresponding yellow row value. Then I want this repeated for every column in the yellow row until there is no more values in the row.

    I couldn't get the concatenate function to work properly, i think the conditional formulas where an issue?

    Thanks!

    MIke
    Attached Files Attached Files
    Last edited by Cutter; 07-23-2012 at 05:39 PM. Reason: Removed whole post quote

  12. #12
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    Ok now I can understand this much better thank you. One last question though, do you plan to keep adding columns on to row 8 or will you just be changing values that are already in there? In other words will values extend beyond column AA?

    ---------- Post added at 11:01 AM ---------- Previous post was at 10:20 AM ----------

    Ok I have it working. for some reason there is an error when I try to upload the file so here is the code:

    Please Login or Register  to view this content.
    Put this in your "Sheet10(Staffing)" and when you change a value in the yellow row it will automatically update the column beneath it. What the code does is every time a value in a yellow cell changes it pastes it into the other sheet and then pastes the resulting column beneath the yellow cell value. I am sure there is a more efficient way to do this (instead of code for each cell do it by range) but I am also new to vb and do not know how to do that. This works just as well though. If in the future you need to add more columns to your "Staffing" sheet copy the code:

    Please Login or Register  to view this content.
    and change the letters in red above to the letters of the new column.

    hth

    EDIT: I figured out the more efficient way:

    Please Login or Register  to view this content.
    hth
    Last edited by carrob; 07-24-2012 at 11:31 AM.

  13. #13
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    carrob! thank you it works! How does one 'like' your post? I don't think I can rep on this forum since I have none myself, haha.


    The only issue is that I can't just paste in a new row of values. If you think of a way that I could refresh all of them with one click, let me know. Otherwise, this is saving me so much time it's absolutely fine.

    Thank you!

    EDIT: it seems to have caused a little delay whenever I change a cell. Any recommendations to speed this up? I'm guessing keep it commented out until I need it maybe?

    Mike
    Last edited by irishman311; 07-24-2012 at 12:15 PM.

  14. #14
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    Glad it works! I think if you click the star in the bottom left of a post it thanks me. I will take a look at the code again.

    ---------- Post added at 01:46 PM ---------- Previous post was at 12:58 PM ----------

    Phew didn't think I was gonna get it to work, here we go:

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    Wow! that is amazing it runs through the whole row when I paste it in! Thank you so much! The only question I have (for future knowledge/use) is that when I assign that macro to a button, rather than have it run on cell change, it gives me an object required warning on the 'set rng' line.

    Thanks! This will definitely work. As for my excel document running much slower now, I may just keep it commented out whiel working on other features. But thank you so much!
    Last edited by Cutter; 07-24-2012 at 06:10 PM. Reason: Removed whole post quote

  16. #16
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    This code will not work on a button. Worksheet_Change is built in and runs when the worksheet is changed: some additional code would have to be added at the beginning to account for this, and I am not sure how to do that. Glad it is working!

    It doesn't run slow on my computer. Does your sheet contain a lot more data than the one you uploaded? I can't imagine what else would be slowing it down.

  17. #17
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    Yes, the sheet has a lot of data and it has been a bit delayed whenever a cell in any sheet is changed. I'm getting used to it though

    So, I am having another minor problem. Basically, I want to continue and add additional changes into each calculation. That is, I want to plug in additional numbers into other cells prior for each computation. I am using offset to pull these values. This seemed to work OK for one instance, but I just added another and it won't work.

    The problem: It uses all parameters from the column in question when a single column is updated. However, when a full row of new data is pasted in, the earliest (furthest left) values in the offset cells are used. They basically do not update 'for each'.

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    Change "Target" to "cel" in:

    Please Login or Register  to view this content.
    I experienced the same issue while writing the code and it took me forever to realize it.

  19. #19
    Registered User
    Join Date
    07-19-2012
    Location
    thailand
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Vba Paste Offset

    strange, with the new code the numbers come out totally different. updating a single cell still is the only way for correct numbers.

    the funny thing is that the .cell changed the references so they don't stick. the weird part.. is that it seems that the column isn't copying properly. that is, now that the macro has ended, I can see that the final values of the output range in input are correct, but they were not correctly copied to the staffing sheet.

    I think that I can deal with updating each cell individually, but any ideas as to why its not copying properly? it i have the right cells selected...

  20. #20
    Registered User
    Join Date
    07-12-2012
    Location
    New Hampshire, United States
    MS-Off Ver
    Excel 2010
    Posts
    80

    Re: Vba Paste Offset

    It's hard to understand what you mean without seeing your full workbook. I tried this:
    Please Login or Register  to view this content.
    with the sample workbook you posted and I believe it worked fine. Just to be sure, make sure you changed "Target" to "cel" and NOT "cell."

+ 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