+ Reply to Thread
Results 1 to 21 of 21

VBA coding concatenate, copy, paste, remove...

  1. #1
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    VBA coding concatenate, copy, paste, remove...

    Hello again all,

    Today was my first attempt to completely write a new code for my job to see if I could do it on my own, and to say the least, I failed.

    Here is the task I am trying to perform:

    - remove ".pdf" from end of file name in columns "E", "I", and "AE"
    - clear contents of column "AD"
    - any cell in column "AP" that is not blank, add ".dwg" to the end of the text

    And now here is my code that is failing

    Please Login or Register  to view this content.


    I am getting an error that says "For without Next" and I have no idea why. As you can probably tell I am completely new to all of this so I could really use a few pointers as to how to get this code (or your own) to work.

    If you have any tips or anything for me as well to explain how I could have attacked this better that would also be greatly appreciated.


    Thanks again and have a great weekend!


    Mike
    Last edited by sk8shorty01; 07-29-2011 at 01:49 PM.

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

    Re: VBA coding concatenate, copy, paste, remove...

    Hi Mike, you are getting the error because of
    Please Login or Register  to view this content.
    there is no
    Please Login or Register  to view this content.
    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
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    So would that code line be the very next line of code I would put in below the first one your linked?

    I am trying to learn as I go, sort of on the fly, and I am taking notes and saving things with tips so I would like to make sure I have it the right way before I head off to doing anything that goes way over my head.

    Thank you for the quick response, other than that does my code look as if it will accomplish everything I am attempting to do? If so, I did at least better than I thought I would haha.

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

    Re: VBA coding concatenate, copy, paste, remove...

    Well, I'm guessing by the code that you've supplied that it should look like
    Please Login or Register  to view this content.

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

    Re: VBA coding concatenate, copy, paste, remove...

    Also, there are multiple ways to get something done using VBA. In saying that, if your code works well, and by well I mean with no errors and runs fast, then I would say that the code is fine.

  6. #6
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    when I run it like that it loops from the clear contents line, down to next cell, then back up to clear contents again.

    It sticks there and cannot go any further.

    If you would be so kind, could you show me how you would have written a code to do what I am attempting? Like I said, I am still learning so the code I supplied you was a butchered attempt at some other codes I have had written for me, and I tried to modify and tailor them to fit my needs. It just has not panned out thus far.

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

    Re: VBA coding concatenate, copy, paste, remove...

    Hi sk8shorty01, I could possibly do as you ask but it would be beneficial to us both if you upload a mock file. The way the code is now, I can debug it without error but I don't know if it will run properly at run-time.

  8. #8
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    Here you go. Let me know if you need anything else.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    And sorry I didnt explain it right before. I need to take the contents of column "AD" move it to column "AP" and then any of those cells within "AP" that contain a value would have to add ".dwg" to the end.

    Then the contents within "AD" needs to be removed.

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

    Re: VBA coding concatenate, copy, paste, remove...

    Hi sk8tshorty01, put the following code into a standard module and let me know if it fulfills your requirements.
    Please Login or Register  to view this content.
    I have revised this code at 11:39 Central Canadian time.
    Last edited by Mordred; 07-29-2011 at 12:39 PM.

  11. #11
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    It worked, however I was wrong yet again and when I tried to modify it I get an error and I am not sure why.

    It should have been "AE" not "AD"

    So I change the code to this and the error I get is "Type Mismatch"

    Please Login or Register  to view this content.

    Any thoughts?

  12. #12
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    also, as another heads up the header bar needs to keep those titles in the columns they are in now.

    So for instance, the info is moving out of the column that says "Drawing No." and is moving into the column that says "Legacy PDF Name", but the title line should remain.

    "Drawing No." does not need to transfer, it should stay as the header for column "AE"

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

    Re: VBA coding concatenate, copy, paste, remove...

    Sorry about the headers, if you'll notice I revise the code a little in post 10 but here is the code with AE instead:
    Please Login or Register  to view this content.
    The reason you were getting an error is more than likely because of the following line
    Please Login or Register  to view this content.
    , specifically,
    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.
    . Copy and paste the full procedure from this post and let me know!

  14. #14
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    is that telling it how many rows to count? What does the 30 or 31 designate? Is that how many cells to move in each row to check for values?

    So AD would be the 30th cell in the row and AE would be the 31st?

    That is my best guess anyways.

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

    Re: VBA coding concatenate, copy, paste, remove...

    Quote Originally Posted by sk8shorty01 View Post
    is that telling it how many rows to count? What does the 30 or 31 designate? Is that how many cells to move in each row to check for values?

    So AD would be the 30th cell in the row and AE would be the 31st?

    That is my best guess anyways.
    It is actually telling the code which Column to set. For instance, Range A2 would be
    Please Login or Register  to view this content.
    where the 2 is the rows count and 1 is the columns count. That being said,
    Please Login or Register  to view this content.
    means that the code will search for the last row
    Please Login or Register  to view this content.
    in column AE (or 31).

    Does this make sense?

  16. #16
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    It worked, I have added a few other things that I needed to do, specifically below:


    Please Login or Register  to view this content.

    The only thing I cannot get to accomplish is to get all contents within column "AD" to be removed. I know it worked before but now that we changed the range value to use "AE" and we clear "AE" I cannot seem to get it to also clear "AD".

    Thanks again, you have been a life saver thus far.

  17. #17
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    that makes sense, thank you very much for helping explain that!

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

    Re: VBA coding concatenate, copy, paste, remove...

    So you want to remove AD as well? For sure? if so, just add
    Please Login or Register  to view this content.
    I didn't test that but it should work, if you want to remove AD as well as AE. Don't forget, once the data is cleared using a procedure, there is no going back to retrieve it.

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

    Re: VBA coding concatenate, copy, paste, remove...

    Here is your full Procedure, revised to remove copy/paste
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    07-14-2011
    Location
    Cocoa Beach, Florida
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: VBA coding concatenate, copy, paste, remove...

    Thanks again, that worked great.

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

    Re: VBA coding concatenate, copy, paste, remove...

    You are welcome.

+ 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