VBA: Searching and extracting

Viewson

New Member
Joined
Feb 8, 2009
Messages
4
Hi All,

From the original sentence below, I am trying to parsing out a certain section in regards to paydate. Then using the second code, I will parse only the paydate. In excel using formula this works, but when trying to work this in a macro, I am getting an error.

Original Sentence: MANDATORY. RIO CA#509513 EX DATE: 3/16/11,PAYDATE:3/23/11.PLEASE CONTACT QC GROUPS LABELS

Code 1: Extract Partial data for Paydate
Code:
 [/FONT]
[FONT=Arial]ActiveCell.FormulaR1C1 = "=IF(AND(ISERR(SEARCH("Payd",G2)),ISERR(SEARCH("Pay d",G2))),"",MID(G2,SEARCH("Pay",G2),20))"[/FONT]
[FONT=Arial]

Output in excel: PAYDATE:3/23/11.PLEA

Code 2: Extract only Paydate
Code:
 [/FONT]
[FONT=Arial]=MID(L4,MIN(FIND(0,SUBSTITUTE(L4,{1,2,3,4,5,6,7,8,9},0)&0)),LEN(L4)-MIN(FIND(0,SUBSTITUTE(L4,{1,2,3,4,5,6,7,8,9},0)&0))-MATCH(1,INDEX(--ISNUMBER(--MID(L4,LEN(L4)+1-
ROW(INDIRECT("1:"&LEN(L4))),1)),0),0)+2[/FONT]
[FONT=Arial]

Final output (Goal): 3/23/11
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi Viewson,
try
Code:
Sub findPaydata()
    startTxt = InStr(1, Cells(2, 7), "PAYDATE") + 8
    endTxt = InStr(startTxt, Cells(2, 7), ".")
    lengthDate = endTxt - startTxt
    myText = Mid(Cells(2, 7), startTxt, lengthDate)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,513
Members
452,921
Latest member
BBQKING

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