+ Reply to Thread
Results 1 to 19 of 19

Check tag presence every N lines of text

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Check tag presence every N lines of text

    Dear all,
    I'd really appreciate your help with a macro or formula that could spare me a lot of time.

    I'm working on a spreadsheet with thousands of cells, each with long texts splitted in lines. Something like this:

    A1:
    Please Login or Register  to view this content.
    Now, I need an automated method to check that there's a <PG> tag every three (3) lines max.
    One or two consecutive lines without a <PG> tag is OK.
    Three consecutive lines without a <PG> tag is a bug.

    Maybe it's an easy task... but I'm going insane.
    Could you help?
    Last edited by Ivan F.; 04-05-2014 at 05:17 PM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Check tag presence every N lines of text

    need a sample txt file (30 rows ) and desired result
    If solved remember to mark Thread as solved

  3. #3
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Check tag presence every N lines of text

    or try something like...
    Please Login or Register  to view this content.
    Highlight the cells to check before running...

    You should include the 'Option Compare...' statement at the top of the module so text comparisons are not case sensitive.
    Last edited by cytop; 04-05-2014 at 02:56 PM. Reason: REvised slightly

  4. #4
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Re: Check tag presence every N lines of text

    Test file.xlsx
    Quote Originally Posted by patel45 View Post
    need a sample txt file (30 rows ) and desired result
    Dear Patel,
    Please, check the XLSX file attached.

    Text in A2 is correct. Text in A3 is NOT correct.
    I'd really need a macro that could tell me that there is an error in A3.
    Any kind of message/highlight/morsecode would be OK!

  5. #5
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Re: Check tag presence every N lines of text

    Quote Originally Posted by cytop View Post
    or try something like...[code]
    [cut]
    Dear cytop.
    Alas, it seems that it doesn't work.
    I've copied the code in the module and saved the file as "xlsm".
    Then, I've selected three cells with text (two with incorrect text) and run the macro.
    An "?" appeared at the end of each line and nothing else.

    Did I do anything wrong?

  6. #6
    Forum Contributor
    Join Date
    12-06-2012
    Location
    sacramento,calif
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: Check tag presence every N lines of text

    Are you pasting text from a web page? Have you tried, Copying the text then use paste special, select html and it will put the text into separate rows. In this case an easy solution is possible.

  7. #7
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Re: Check tag presence every N lines of text

    Quote Originally Posted by JJGF View Post
    Are you pasting text from a web page? Have you tried, Copying the text then use paste special, select html and it will put the text into separate rows. In this case an easy solution is possible.
    Dear JJGF.
    No, I'm not pasting from a web page.
    Still, I can paste the text into Word, then paste back in Excel.
    It will put lines into separate rows.

    A few passages, but not a problem for me.
    But then?

  8. #8
    Forum Contributor
    Join Date
    12-06-2012
    Location
    sacramento,calif
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: Check tag presence every N lines of text

    I'll try to the best of my knowledge,
    Can you try first copy the text, then on the home tab (Excel 2010) click on paste with arrow down then select text?

  9. #9
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Re: Check tag presence every N lines of text

    Quote Originally Posted by JJGF View Post
    I'll try to the best of my knowledge,
    Can you try first copy the text, then on the home tab (Excel 2010) click on paste with arrow down then select text?
    Thanks a lot, JJGF.
    Yes, I can do what you ask, but I'm not sure of the expected result.

    Note that I can copy/paste/manipulate the cells in any way needed.
    I don't mind if the solution needs three steps and a few minutes of work.
    If it works, I could spare literally hours

  10. #10
    Forum Contributor
    Join Date
    12-06-2012
    Location
    sacramento,calif
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: Check tag presence every N lines of text

    Quote Originally Posted by Ivan F. View Post
    Dear JJGF.
    No, I'm not pasting from a web page.
    Still, I can paste the text into Word, then paste back in Excel.
    It will put lines into separate rows.

    A few passages, but not a problem for me.
    But then?
    If you are able to get the text into rows, try the attached file, just run the formulas down (in Col E and F) to cover all the text in the A column.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    12-06-2012
    Location
    sacramento,calif
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: Check tag presence every N lines of text

    The formula will check every line with a <pg> and if there is not another <pg> within 4 lines down, it will say "check line"

  12. #12
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Check tag presence every N lines of text

    Misunderstood your original requirement... it checked individual rows on the worksheet, not lines in a cell. I also can't understand where the '?' you mentioned comes from. To avoid any issues, copy of your workbook attached. This works with your original layout where the text is in cells rather than rows.

    Run the code in the worksheet class module for sheet1 manually...

    Test file.xlsm

  13. #13
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Re: Check tag presence every N lines of text

    Quote Originally Posted by JJGF View Post
    The formula will check every line with a <pg> and if there is not another <pg> within 4 lines down, it will say "check line"
    Ingenious indeed
    It needs a tweak or two (such as adding a <PG> tag at the beginning and at the end of each original string: 10 seconds of work with a formula), but I'm pretty sure it'll work.

    Thank you, JJGF!

  14. #14
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Re: Check tag presence every N lines of text

    Quote Originally Posted by cytop View Post
    Run the code in the worksheet class module for sheet1 manually...
    A few "run the code" later…
    It works like a charm!

    Using Excel for Mac, I changed the delimiter (from VBLF to VBCR), and now it works on my Mac as well.

    Marked the thread as SOLVED.
    Added reputation to your last post.

    Please, Cytop, let me know via PM if I can thank you with a little gift
    (Amazon/Spotify/PSN card or something similar)

  15. #15
    Forum Contributor
    Join Date
    12-06-2012
    Location
    sacramento,calif
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: Check tag presence every N lines of text

    Quote Originally Posted by Ivan F. View Post
    Ingenious indeed
    It needs a tweak or two (such as adding a <PG> tag at the beginning and at the end of each original string: 10 seconds of work with a formula), but I'm pretty sure it'll work.

    Thank you, JJGF!
    Glad to help, I only wish I could provide something better with VB

  16. #16
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Check tag presence every N lines of text

    Please, Cytop, let me know via PM if I can thank you with a little gift
    A very kind offer, but I'll keep the reply public...

    THe Rep is payment enough, thank you. However, if you feel the need to dispose of some of your hard earned cash then please consider a small donation to a charity - my choice would be dogs or kids (after rearing both I know which I prefer!) - but the choice is yours.
    Last edited by cytop; 04-05-2014 at 05:34 PM.

  17. #17
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Re: Check tag presence every N lines of text

    Quote Originally Posted by cytop View Post
    A very kind offer, but I'll keep the reply public...

    THe Rep is payment enough, thank you. However, if you feel the need to dispose of some of your hard earned cash then please consider a small donation to a charity - my choice would be dogs or kids (after rearing both I know which I prefer!) - but the choice is yours.
    Dear Cytop,
    I'll do this, thanks again.

    A little note for other users who wants to try the code…
    It seems it's still necessary to add a <PAGE> tag at the end of each cell, in order for the macro to run properly.
    You can do this using a simple formula.
    If your text is in column A, insert this in column B:
    Please Login or Register  to view this content.
    Then, copy back in column A the text as value.
    A few seconds of extra work, nohing else.

  18. #18
    Registered User
    Join Date
    05-08-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel for Mac
    Posts
    11

    Re: Check tag presence every N lines of text

    Quote Originally Posted by cytop View Post
    Misunderstood your original requirement... it checked individual rows on the worksheet, not lines in a cell. I also can't understand where the '?' you mentioned comes from. To avoid any issues, copy of your workbook attached. This works with your original layout where the text is in cells rather than rows.

    Run the code in the worksheet class module for sheet1 manually...
    Hi cytop, hi all!
    Sorry to bother (13 months later!), but' I'd really need your help to tweak this excellent code.

    If you remember, I needed to check if a tag was present every THREE lines of text.
    Now, I need to check if a tag is present every EIGHT (8) lines of text.

    This was the original (perfectly working) code:
    Please Login or Register  to view this content.
    Could you (or other kind users) please help?

    Thanks in advance!
    Last edited by Ivan F.; 06-10-2015 at 06:05 AM.

  19. #19
    Forum Contributor
    Join Date
    12-06-2012
    Location
    sacramento,calif
    MS-Off Ver
    Excel 2010
    Posts
    217

    Re: Check tag presence every N lines of text

    TRY:

    Please Login or Register  to view this content.
    Last edited by JJGF; 06-13-2015 at 08:31 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I need a code for presence check to check multiple text boxes and combo boxes
    By Lee_wwfc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2013, 01:53 PM
  2. [SOLVED] How to check two columns for the presence of text and returning "yes" or "no"
    By Karelia Suite in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-19-2013, 09:36 AM
  3. Conditional format to check for entry presence in multiple worksheets
    By Bearded Dan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-02-2012, 04:47 PM
  4. Check for presence of value in range
    By JChandler22 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-16-2009, 12:01 PM
  5. COUNTIF according to presence of string within text
    By Ingeniero1 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-01-2006, 02:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1