+ Reply to Thread
Results 1 to 10 of 10

Loop to find a cell, then copy offset paste

  1. #1
    Registered User
    Join Date
    02-01-2009
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2003
    Posts
    9

    Loop to find a cell, then copy offset paste

    Hello. Really new at VB in excel, and would love any help woth a work assignment.

    I have a data sheet with employee information. Only one column. It prefixes information with codes, but keeps it in the same cell. I want to move data of certain types into their own columns, but the amount of data is variable, so I cannot simply move every Nth cell, etc.

    i.e.

    Employee#1
    200 Firstname Lastname
    204 99999999 (Employee ID)
    G38 00005000 (i.e. Pension Deduction)
    H38 00007580 (i.e. Benefits Deduction)
    X96 00012099 (i.e. Staff Club Deduction)
    Employee#2
    200 Firstname Lastname
    204 99999998
    G38 00000775
    X96 00001000

    So you see some employees may have different codes altogether. But I know that I want all the cells that start with 200 to be offset (-1,1), and all the cells that start with 204 to be offset (-1,2), and so on so that basically I end up with columns of info instead of a one column list.

    I have been reading and studying other peoples' macros, and am just starting to grasp the basic. When I wrote my own to accomplish this, I put this together, which doesn't work. But I don't know enough to know what I don't know.

    Please Login or Register  to view this content.
    What I have so far finds what I am looking for, copies it but the paste fails.
    Last edited by mr.alexander; 02-07-2009 at 11:56 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Loop to find a cell, then copy offset paste

    Welcome to the forum.

    Try this:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-05-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    17

    Smile Re: Loop to find a cell, then copy offset paste

    Hi Mr Alexander

    Here is a basic version that will give you an idea.

    What you need to remember for this to work correctly is that every employee does not have any empty cells, e.g. even if they dont have a staff discount that cell must still contain the search prefix number so that all data will tally up with the right Staff member.


    Regards
    Attached Files Attached Files
    Last edited by Strugglin; 02-01-2009 at 08:32 PM.

  4. #4
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: Loop to find a cell, then copy offset paste

    Hi

    Here is another for you to try, the destination for all is on the "200" line for convenience but can be placed anywhere.

    Regards

    Jeff
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Loop to find a cell, then copy offset paste

    Hi

    Yet another approach. This one will build a list of the headings from the data, and split it out.

    Please Login or Register  to view this content.
    rylo

  6. #6
    Registered User
    Join Date
    02-01-2009
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Loop to find a cell, then copy offset paste

    Wow. I am overwhelmed at the knowledgable help that I received here! Thank you so much.

    shg : your post technically answered my question and it was really helpful to see what I was doing wrong. But once I got it going, I realized that what I had started writing was not going to do the trick.

    strugllin, solnajeff and rylo : you discerned what I was trying to accomplish, and showed me some great codes.

    With the type of data I am working with and the type of report that I need to produce, SolnaJeff's transpose macro would work best for my particular needs. But I am struggling a bit to modify it to my needs.

    I have modified the sample transpose sheet and included sample data that i am working on. I have anonymized the data. What I am attempting to do is to include the employee number. It is hidden in the data and I am using a mid function to extrapolate, but I am using the wrong logic and this addition is being ignored. The employee number is the 4 digits starting at the 15th character in the rows that begin with "#", which are always above the "200" row. The 200 row is d, which led me to try this logic:

    Let eeid = Mid(Cells(d - 1), 15, 4)
    Let Cells(d, 2).Value = eeid

    Can someone tell me what it is that I am misunderstanding?

    Thank you!
    Attached Files Attached Files
    Last edited by mr.alexander; 02-02-2009 at 12:25 PM.

  7. #7
    Registered User
    Join Date
    02-01-2009
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Loop to find a cell, then copy offset paste

    Ok, I played with it until I found the answer, and I think I have it now.

    Here is the final product, and it seems to work very well.

    It strips out the codes I don't need, then adds the column headers, then does the transpose feature that you gave to me, then deletes the source column and blank rows. Thank you all for your help. With a few more minor tweaks, this macro will save me an hour a week!

    Please Login or Register  to view this content.
    Thanks to all!

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Loop to find a cell, then copy offset paste

    Your post does not comply with Rule 9 of our Forum RULES. If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit. And please never edit a thread in which someone else has responded.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  9. #9
    Registered User
    Join Date
    01-29-2013
    Location
    Poland
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Loop to find a cell, then copy offset paste

    hello, i need macro to find value in column A(level) (in next column are values too), after find this value, cut all data from this row and move right to defined offset.

    eg line with level:

    0 not move
    1 not move
    2 move right one position all data with this line
    3 move right two position all data with this line
    4 move right three position all data with this line
    5 move right four position all data with this line




    I have to make tree structure

    my macro is:

    Please Login or Register  to view this content.
    but move only one cell right (i need all data from line move right to define position)
    please help
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by arlu1201; 01-29-2013 at 08:46 AM.

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Loop to find a cell, then copy offset paste

    Wacholec1985,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.

    Also,

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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