How do I set conditions before using "split"

zany username

New Member
Joined
Jun 14, 2014
Messages
6
I'm completely new to VBA but I found some very helpful code in an older thread: http://www.mrexcel.com/forum/excel-questions/543349-extract-text-between-two-points.html

Using "Split":

Code:
Public Sub Test1()

Dim oTarget As Range
Dim oCell As Range

Set oTarget = ActiveSheet.Range("A2:A2043")

For Each oCell In oTarget

oCell.Offset(0, 4).Value = Split(Split(oCell.Value, "Date_stamp:")(1), "Payment_made:")(0)

Next oCell

End Sub

Thanks Gary, that's accomplised what I was originally failing to do with MID() :) but what I'm hoping someone can show me now is how I can set conditions on using Split.


I have dumped data from emails into Excel 2010 in cells A2:A2043 and I'm spliting it for ease of viewing but I need the code to check if the cell contains a specific string and if skip to the next cell if it doesn't. For instance when the customer hasn't made a payment it will skip as there isn't anything to split after that point and continue spliting if they answered Yes.
Examples are:
Customer_Number: 11338849

Invoice_Period: 30/06/13

Attendance_type: Group

BookingDate_stamp: 03/07/2013

Payment_made: No
Customer_Number: 11338849

Invoice_Period: 30/06/13

Attendance_type: Group

BookingDate_stamp: 03/07/2013

Payment_made: Yes

Payment_method: Cheque

Payment_date: 14/06/2013


<TBODY>
</TBODY>

Ideally I would have extracted directly from Outlook but that's a different problem for another day at this stage, so I wan't to carry on from where I am. Also, how am I going to extract that last date :eek: Can I Split between "Payment_date:" and the end of the cell?

Best regards,
Zany
 
Ah, no it's Payment_made: Yes. But I've corrected that and it's still not working. The sub-strings are:

Customer_Number: 11338849

Invoice_Period: 30/06/13

Attendance_type: Group

BookingDate_stamp: 03/07/2013

Payment_made: Yes

Payment_method: Cheque

Payment_date: 14/06/2013


I eventually had to alpha-sort the spreadsheet based on Yes/No in column 5 and start the script from halfway through where all the proceeding cells were Payment_made: Yes.
And I resorted to using FIND("_date:",A:A) to get the position of the payment date and refernced that result with =MID(A:A,J38,17) to extract _date: 14/06/2013. What would be a better way to get the value for Payment_date?
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,216,100
Messages
6,128,824
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top