+ Reply to Thread
Results 1 to 22 of 22

Auto Population

  1. #1
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Auto Population

    Ok, so this is my first attempt at an excel macro. I'm trying to develop a macro that will assist me in auto-populating a column in a new worksheet based on another worksheet. Recently I ran a new report at work that is 4000 lines long that I really do not want to have to edit by hand, since I already had to do it with the older one.

    I can't post my data but i'll try to explain it the best I can, but basically it's set up as a part number, next column is the steps in completing that part, and then a workcenter number. I'm trying to populate that workcenter column in the new worksheet. I've put this macro together with the best of my ability along with excel help and the internet but I just can't seem to get it to work.

    Please Login or Register  to view this content.
    When I step through it it seems to fail at the line Range("A1").Select and I'm not sure why, any advice would be appreciated, or if my code is completely wrong and tips to point me in the right direction would be appreciated.

    Thanks in advance,
    J
    Last edited by JustinZ; 10-26-2009 at 09:25 AM.

  2. #2
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Try removing this line:
    Please Login or Register  to view this content.
    You shouldnt have to go to cell A1 to perform a find in excel.

    All of the ".Select" could be ".Activate". You really do not need to select cells.
    Regards

    Rick
    Win10, Office 365

  3. #3
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    I tried your suggestions and it runs a little farther through the program, but I can't seem to get the find to work. My intentions were for the program to set the old part number as a variable and then search for it, did I not execute this properly?

  4. #4
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Can you attach a sample workbook!?

  5. #5
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    surely, here it is.
    Attached Files Attached Files

  6. #6
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Is there a worksheet missing?
    "SFC times by plan"

  7. #7
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    "SFC times by plan" is SFCTimesOld I thought it would be easier if i clarified them as old and new versus their default names, I'm probably going to change them in the real file as well so feel free to change them if you have a correction idea for consistency purposes.

  8. #8
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Which sheet is the starting sheet?
    SFCTimesOld or SFCTimesNew

  9. #9
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    I'm attempting to read from the SFCTimesOld sheet to populate the SFCTimesNew sheet.

  10. #10
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Auto Population

    I think it would help Rick or anyone else if you could post a workbook which resembles your actual one and including the code. That way we can test it ourselves. You appear to be locating a part number and then searching for it, which seems odd but I may have misunderstood.

  11. #11
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    I've attached a snipet of my actual data and the macro i've currently attempted, if you need anything else just ask.
    Attached Files Attached Files

  12. #12
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Just an FYI
    part of the problem is this portion of code:
    Please Login or Register  to view this content.
    Once you get to the end of the list of values, there will not be any match to varOperNo. The loop will continue to the last row, where you try to offset to a row that doesnt exist.

  13. #13
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    hmm, thank you for pointing that out, I'll have to look into a new way to try to do that, I never noticed that would be a problem.

    Also, my current problem is the find, i cannot get it it to work, it comes up unfound every time. I thought my problem was not identifying a starting point to search (something like range("A2").activate) but every time i tried that it errored so i'm stuck.

  14. #14
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    The find is finding the value, the code is backwards.

    Try this code: It searches the usedrange, not the entire 16,384 rows.
    Please Login or Register  to view this content.
    This message box
    Please Login or Register  to view this content.
    shows the address of the "pnfind" variable.

    This leads to the next error.
    Please Login or Register  to view this content.
    The code in Red will fail because there is no value 6 rows down.

    Perhaps you can explain what needs to be copied from which cells to which cells.
    Seems like you are changing worksheet row/column formats (headings etc.)?
    Last edited by Rick_Stanich; 10-22-2009 at 04:13 PM.

  15. #15
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    Maybe a little background will help, a few months ago we started a project that dealt with determining and assigning new work centers to all our machines, and we went through what would be SFCTimesOld and manually input all the new work centers. Now a few months later we reran the report but I don't want to spend the hours it took to manually do it again, and since almost all the parts are still the same, I wanted to use SFCTimesOld to populate the new work center numbers in SFCTimesNew based on part number and operation.

  16. #16
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    Ok, i tried your find suggestion and the message box output "$A$2" which is right but then it seems to get caught in an infinite loop among this code:

    Please Login or Register  to view this content.
    also the line you highlighted in red was a typo and it actually should have read (0,6) not (6,0) so i fixed that.

  17. #17
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Deleted text
    Last edited by Rick_Stanich; 10-23-2009 at 10:38 AM.

  18. #18
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Are you wanting to copy data by Part Number, Operation Number and Work Center (only those cells) to the new sheet, or all data from sheet1 to sheet2 into relative cells?
    Eample:
    You have 8 operations on sheet1 and 10 operations on sheet2 for part number 12345.
    Thus do you want to copy just work center value to sheet2 only if there is a matching operation or all relative data including all operations?

    Excuse the time delay's, I am looking at this between my projects.
    If its any consolation, I am in manufacturing as well.

  19. #19
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    One of my biggest problems was that report was spit out in 2 different formats since there was about 8 months between when we ran them, but I'm only looking to copy the new work center based on part number, then operation number.

    The time difference is no big deal as I'm juggling this between projects as well, I just appreciate the help, i'm can do just about anything in excel except macros.

  20. #20
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Ok, lets give this a try.
    Notes:
    The macro works on a "Used Range". Any errant data beyond Column N may cause unforseen problems.
    Color coding is a visual aid for programming. It is not needed.
    Duplicate worksheets (2) respectively, were to cover my behind incase I screwed it up.
    I added a "Status Bar" text message (That’s the lower left hand corner of the Excel wondow, typically shows the word "Ready".
    Let me know how the status bar works on large data. It appears to work fine on this small amount of data.

    Instructions: (pertains to this workbook only)
    Click on the CommandButton at the top of the worksheet.
    Switch between worksheets to verify data transfers.
    HTH

    Man, I hope I got this right, I was popping brain cells by the bazillions. LOL
    Attached Files Attached Files

  21. #21
    Registered User
    Join Date
    10-22-2009
    Location
    Peckville, PA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Auto Population

    It works! Thank you so much for your help, what you did makes a lot more sense than the way I was attempting it lol. Hopefully I can take this and learn more about macros, thanks again.

    -J

  22. #22
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,163

    Re: Auto Population

    Just make sure you run the macro on "copies", proof read some of it, then go ahead and use it.

    Glad I could help.

+ 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