zookeepertx
Well-known Member
- Joined
- May 27, 2011
- Messages
- 586
- Office Version
- 365
- Platform
- Windows
Hello all!
I have a question that I posed a while back and received excellent help on! But now I've been informed that there a few new scenarios that need to be handled and I can't figure out how to get the macro to recognize them.
I'm at work and am not allowed to download any applications, etc that would allow me to post a spreadsheet here, so I'll have to show a table with the data and hope you all don't mind that.
Here's an example of my raw data. I'm only concerned with the data in column F (PO), so I'll leave the other columns blank, just to make it less cluttered.
Below that I'll post my original request and the new problem and the solution code I was given to take card of the original request:
The existing code below correctly removes that information that I've colored purple in the table above. My problem is that I need to ALSO get rid of the information that I've colored red in the table. I only need to keep the information that's colored black in the table.
I've tried numerous adjustments in the code to handle the new patterns in the data (which I wish my co-worker had told me about in the beginning), but am getting absolutely nowhere. Either it has no effect at all or it causes an error message.
Just as a side note, in the existing code, I understand .Pattern="\d{11}/\d{4}|\d{4}/\d{11}" but I don't get what .Pattern="(\d{11})(.+)(\1)" is looking for. If someone could enlighten me on that, it'd be great!
I really appreciate any help you can give me! This board has saved my bacon so many times already, too!
Jenny
I have a question that I posed a while back and received excellent help on! But now I've been informed that there a few new scenarios that need to be handled and I can't figure out how to get the macro to recognize them.
I'm at work and am not allowed to download any applications, etc that would allow me to post a spreadsheet here, so I'll have to show a table with the data and hope you all don't mind that.
Here's an example of my raw data. I'm only concerned with the data in column F (PO), so I'll leave the other columns blank, just to make it less cluttered.
Below that I'll post my original request and the new problem and the solution code I was given to take card of the original request:
Import Invoice | Origin | Dest | Cartons | HAWB | PO | Shipper | Vendor Called for Booking | Cargo Ready Date | Shipment Pickup |
10100591452/8113 10100601841/8113 10100601841 10100591452 | |||||||||
9289 10100612579/2026 10100612579 | |||||||||
NONE | |||||||||
10100610339 10100610339-7079 | |||||||||
DN-02608 10100598256 10100598256/4447 | |||||||||
NA 10100622117 10100622117/2025 | |||||||||
NA 10100559684 | |||||||||
10100620443 NA | |||||||||
NA 10100601761/2026 10100601761 | |||||||||
10100563829 10100563829/8164 | |||||||||
10100563829 | |||||||||
DN-32039 10100563829 |
The existing code below correctly removes that information that I've colored purple in the table above. My problem is that I need to ALSO get rid of the information that I've colored red in the table. I only need to keep the information that's colored black in the table.
VBA Code:
Set r = Range("F2", Range("F" & Rows.count).End(xlUp))
With CreateObject("VBScript.RegExp")
.Global=True
ForEachrCInr
.Pattern="\d{11}/\d{4}|\d{4}/\d{11}"
s=.Replace(rC.Value,"")
.Pattern="(\d{11})(.+)(\1)"
While.Test(s)
s=.Replace(s,"$1$2")
Wend
rC.Value=Application.Trim(Replace(s,"PO",""))
NextrC
End With
I've tried numerous adjustments in the code to handle the new patterns in the data (which I wish my co-worker had told me about in the beginning), but am getting absolutely nowhere. Either it has no effect at all or it causes an error message.
Just as a side note, in the existing code, I understand .Pattern="\d{11}/\d{4}|\d{4}/\d{11}" but I don't get what .Pattern="(\d{11})(.+)(\1)" is looking for. If someone could enlighten me on that, it'd be great!
I really appreciate any help you can give me! This board has saved my bacon so many times already, too!
Jenny