PDA

View Full Version : Macro to select every row that begins with a certain character



bobsacaman01
04-04-2011, 03:30 PM
Hi, I was wondering if anyone knows of a way to write a macro to be able to select every row that begins with a certain character. For instance "A" or "C". After each row that contains (for example "A") is selected I would then like to copy or cut and paste these instances into another word document.

This is a little off topic of my original post, but along those same lines... Some of the data I'm working with ends up on the next line. So is there a way to backspace (not sure if that's the correct word) every line that does not begin with said certain character, (for instance "A") to adjoin it on the previous row to make all the data matchup up with my orginial certain character?

Currently I'm going through and hitting backspace every place that doesn't contain "A" to get the runoff data back on the same row with the original string.

Hope this makes sense... the following is an example of the data I'm working with:


A 1 10 A37 Davis Hooper R . . . 3 AU40 Davis
Demario
A 2 7 A40 Davis Hooper R . . . 1 AU41 Byrd Najel
A 3 6 A41 Barrett Trotter P C Derek Winter 13
ASU46 AU Bates Graham
A 1 10 K46 Davis Hooper R . . . 6 ASU40 Draper Amos
A 2 4 K40 Davis Hooper R . . . 3 ASU37 Davis
Demario
A 3 1 K37 Davis Hooper R . . . 2 ASU35
AU Davis Demario Bates Graham
K 1 10 K22 Robertson Je R . . . 5 ASU27 Jessel
Curry Kenneth Carter
K 2 5 K27 Butterfield P P C Smith Andre 5
ASU32 ASU Eltoro Freeman
K 1 10 K32 Butterfield P P C McCants Carlos 11
the ASU43 ASU Chris Davis
K 1 10 K43 Lawson Derek R . . . 2 ASU45 Kenneth
Carter
K 2 8 K45 Butterfield P P C Smith Andre 14
the AU41 ASU
K 1 10 A41 Butterfield P P I Fleming RJ
K 2 10 A41 Butterfield P P C McCants Carlos 9
AU32 Chris Davis
K 3 1 A32 Robertson Je R . . . 0 AU32 Kenneth
Carter
K 4 1 A32 Robertson Je R . . . 3 AU29
ASU Mike McNeil
K 1 10 A29 Butterfield P P C Henderson L 6
AU23 Eltoro Freeman
K 2 4 A23 Robertson Je R . . . -1 AU24 T'Sharvan
Bell Nosa Eguae
K 3 5 A24 Butterfield P P I McCants Carlos QB hurry
by Jessel Curry QB hurry by Corey Lemonier

macropod
04-04-2011, 04:41 PM
Hi Bob,

It's not clear what you mean with the first part of the question - I can't see how that relates to the data you've posted or to the second question. However, it seems you should be able to use a wildcard Find/Replace to find every paragraph that doesn't begin the A or C and delete those paragraphs. Whatever's left could then be saved to a new file.

For the second question's issue of lines not starting with 'A', a wildcard Find/Replace will do the job, where:
Find = ^13([!A])
Replace = \1

bobsacaman01
04-05-2011, 09:24 AM
Hi Paul,

Thanks for pointing me in the right direction with the wildcard find and replace for the second part of my question.

Sorry the first part was confusing... I meant to type "K" instead of "C" so that it matched my example data.

I think the wildcard find/replace would also work for the first part of my question. What kind of formula would I need to find every paragraph or line that doesn't start with "A" to be able to delete that text? I can provide more data if needed.

Thanks for taking the time with my question, I appreciate your help!

macropod
04-05-2011, 02:13 PM
Hi Bob,

In that case, you'd use a wildcard Find/Replace to clean up the 'wrapped' lines, coded as:
Find = ^13([!AK])
Replace = \1
(which takes care of the 2nd part of your question), then, to delete all paragraphs not beginning in K, you'd use another another wildcard Find/Replace, coded as:
Find = ^13[!A][!^13]{1,}
Replace = nothing
If your first paragraph begins with a letter other than A, you'll need to delete that manually afterwards. You can then save what's left as a new document. Change the 'A' in the Find/Replace code to suit whatever letter you're filtering for.

bobsacaman01
04-05-2011, 02:53 PM
Wow! That is EXACTLY what I was looking for. Thank you so much for your help, you made my sorting through this data a whole lot easier!