VBA Code "LIKE" statement only copying first instance found

tyantorno
NewLounger
Posts: 3
Joined: 21 Nov 2012, 15:49

VBA Code "LIKE" statement only copying first instance found

Post by tyantorno »

Hello,

I have uploaded the file.Basically what I do is Run step 1, this runs in succession step 1 to step 1_6. The Step 1_7 is the issue. I am trying to copy AL-JEFF..Consumers, AL-JEFF...Sales,AL-JEFF... Sellers. The Program only seems to copy AL-JEFF..Consumers, which is the first in the list. I am relatively new to VBA so the code is sloppy I know, but learning new things every hour. I think is have to do with I need to add a ApplicationCutCopy = False maybe? I know the previous sub routines are causing it because when I just put code in fresh worksheet with data it runs. Thank you for all you help. Tom
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA Code "LIKE" statement only copying first instance fo

Post by HansV »

Welcome to Eileen's Lounge! I'll take a look at your workbook.
Best wishes,
Hans

tyantorno
NewLounger
Posts: 3
Joined: 21 Nov 2012, 15:49

Re: VBA Code "LIKE" statement only copying first instance fo

Post by tyantorno »

Thank you for the invite, very nice forum almost cozy lol.

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA Code "LIKE" statement only copying first instance fo

Post by HansV »

The problem is in Step1_3. You split the string on ";" but in fact, the values are separated by "; " i.e. a semi-colon followed by a space.
As a result, the first value you get is "AL-JEFFERSON CO Consumer Use Educ Tax", which is OK, but the second is not "AL-JEFFERSON CO Sales/Education Tax" as you intended but " AL-JEFFERSON CO Sales/Education Tax", and so on for the rest. As a result these values do not start with "AL", so they don't meet the criteria.

One option is to replace "; " with ";" in the strings. Another is to change the split statement to

Code: Select all

    ary = Split(.Cells(i, "F"), "; ")
I will post this in your thread on MSDN too (VBA Code "LIKE" statement only copying first instance found not all instances in column F).
Best wishes,
Hans

tyantorno
NewLounger
Posts: 3
Joined: 21 Nov 2012, 15:49

Re: VBA Code "LIKE" statement only copying first instance fo

Post by tyantorno »

Thank you again, you are a lifesaver

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA Code "LIKE" statement only copying first instance fo

Post by HansV »

You're welcome! Feel free to start a new thread if you have more questions.
Best wishes,
Hans