+ Reply to Thread
Results 1 to 25 of 25

VBA assistance to modify code

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    9

    Smile VBA assistance to modify code

    Hello All,

    I have a piece of code that almost works for what I need it to do.
    Basically, I have data consisting of a variable number of column separated
    strings. example

    01AL,02AL,03AL,04AL

    When I run the code below

    Please Login or Register  to view this content.
    It gives me sixteen rows of:

    01AL
    02AL
    03AL
    04AL
    01AL
    02AL
    03AL
    04AL
    01AL
    02AL
    03AL
    04AL
    01AL
    02AL
    03AL
    04AL

    and a #VALUE down the rest of the column

    I was hoping to only get four rows of:

    01AL
    02AL
    03AL
    04AL

    with no #VALUE down rest of column.

    Thank you in advance for any assistance/suggestions.


    Moderator's Note: Please put code tags around codes, select the code then hit "#" sign. I'll do it for you, this time.
    Last edited by vlady; 11-19-2012 at 07:45 PM. Reason: code tags

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA assistance to modify code

    You need to resize the range you are putting the values in.

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA assistance to modify code

    one way:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    10-25-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA assistance to modify code

    Hello Norie,

    That took care of the #VALUE, but still have sixteen rows of data with a new row inserted between each.
    Thank you.
    Last edited by tyantorno; 11-19-2012 at 01:02 PM. Reason: did not put in name

  5. #5
    Registered User
    Join Date
    10-25-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA assistance to modify code

    Hello TMS,

    That does work, but the problem is I can a variable amount of commas separated cells with a variable amount on names. Thank you looking at my post.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA assistance to modify code

    When I run the code I only end up with 4 rows of data.

    That was with 01AL,02AL,03AL,04AL in A1, what data do you have exactly?

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA assistance to modify code

    I'm not entirely sure what you are saying. This code lists 12 cells:

    Please Login or Register  to view this content.

    the number of commas is irrelevant.

    Regards, TMS

  8. #8
    Registered User
    Join Date
    10-25-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA assistance to modify code

    Quote Originally Posted by Norie View Post
    When I run the code I only end up with 4 rows of data.

    That was with 01AL,02AL,03AL,04AL in A1, what data do you have exactly?
    Hello Norie,

    I can have a variable number of comma separators and a variable of data e.g. 01AL,02AL or AK05,AK06 in column B. I am on 2007 Excel. Thank you.
    Last edited by tyantorno; 11-19-2012 at 01:54 PM.

  9. #9
    Registered User
    Join Date
    10-25-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA assistance to modify code

    Hello TMS,

    Please see post above concerning variable amount of commas as well as data. Thank you.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA assistance to modify code

    I realise you have multipe cells and multiple comma-separated values in the cells.

    But what data do you have when the result is 16 rows of data with blanks inbetween?

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA assistance to modify code

    Why don't we stop trying to second guess what your workbook, worksheet and data look like and you post a sample workbook with some typical data.

    If you mock up what you want to see as output given specific input, I'm sure we can make it happen for you.

    As it is, I'm losing interest ...

    Regards, TMS

  12. #12
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA assistance to modify code

    Hi,

    Let me jump in here with an example of what I think you want and some code.

    Here is how I'd do this problem. I took the column A and made what I think you want in Column B. I'd then delete column A to get exactly what I think you want.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA assistance to modify code

    Maybe this:

    Please Login or Register  to view this content.

    Regards, TMS

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA assistance to modify code

    @MarvinP: I hadn't noticed a requirement to remove duplicates. But, if there is one, why do you need to sort the output?

    Regards, TMS

  15. #15
    Registered User
    Join Date
    10-25-2012
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA assistance to modify code

    I am sorry for the confusion. I have attached raw data and images if it helps. Basically, I have code that splits out the comma separated but if there are three commas which will be four strings it copies down the row sixteen rows. What I am trying to do is only copy down the same number of rows i.e. four or the strings of data. I hope images and raw data help. Sorry again.
    Attached Images Attached Images
    Attached Files Attached Files

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA assistance to modify code

    You have the same list of four values in 5 rows, do you want one of the rows deleted?

  17. #17
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA assistance to modify code

    Hi,

    In his first post I found the result was filtered and sorted. I put filter and sort as separate subs so he could see them and the code for each sub function.
    Last edited by MarvinP; 11-19-2012 at 06:16 PM.

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA assistance to modify code

    Marvin

    First post?

    Do you mean another thread?

  19. #19
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA assistance to modify code

    Hi,

    Run the macro with your name on it, with column J cleared of any data. I think this is what you want.
    Attached Files Attached Files

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA assistance to modify code

    Marvin

    That copies, sort and dedupes.

  21. #21
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA assistance to modify code

    @Marvin: are you confusing this thread with something else you're working on?

    There's only an excerpt of code without Code tags, no workbook and a very limited explanation of the requirement.

    The first workbook example was in post #15


    Regards, TMS

  22. #22
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: VBA assistance to modify code

    Just looked at the sample workbook. No way would I have guessed that the data looked like that, nor what was required.

    All yours, guys.

    TMS

  23. #23
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VBA assistance to modify code

    Hey TM,

    I wasn't confused. Sorry - but sometimes stuff just seems to make sense to me only.

    Let me explain. I'm a For Next kind of guy. I saw his original code and saw what I thought was the problem. I didn't read his code and simply created my own sheet with his kind of data and wrote code to get to what I thought he wanted. I used Col A and B for my code. After he posted an example workbook it was easy to change the columns and run the code again.

    I really don't understand some of these questions but I thought I did understand this one and it seemed to work for the OP.

  24. #24
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Marvin

    I'm confused.

    Where did the OP mention putting the values in column J?

    The original code was for column A and in the sample data it appears to be column B, no column J unless I missed it.

  25. #25
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA assistance to modify code

    Final shot.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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