+ Reply to Thread
Results 1 to 9 of 9

VBA - Repeat Text until reach New Text

  1. #1
    Registered User
    Join Date
    06-27-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    9

    VBA - Repeat Text until reach New Text

    Hi,

    I'd like some help with the following problem.

    I've got some data that sits under heading rows, but I would like to duplicate the heading against the data set that falls under that heading (creating a bit of a database).

    In the attached Example workbook, I've got a preview of what I would like in Columns I-L, and the fields I would like to populate with this data in A-D.

    The data set is often thousands of rows, so i'd like the macro to repeat until it reaches the end of my data set. The check for the end of the data set would need to check if the next 30 or so rows are blank, terminate (unless their is a function to find where the last cell with data in it sits.

    Example Workbook 130628.xlsx

    Thanks in advance.

    Declan.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA - Repeat Text until reach New Text

    Try this,
    And if you are going to have that many lines, you will need something efficient.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JapanDave; 06-28-2013 at 02:54 AM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    06-27-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA - Repeat Text until reach New Text

    Dave,

    Thanks for that.

    I do however encounter a problem: where the Line number is more than one digit the above code can not handle that.
    Also, the code you have written(excuse my ignorance as I am new to VBA) would you classify it as efficient? and how can I repeat it for my entire data set?

    Regards,

    Declan.

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA - Repeat Text until reach New Text

    Quote Originally Posted by oglion View Post
    I do however encounter a problem: where the Line number is more than one digit the above code can not handle that.
    I thought I took into account for that. Let me check it, I will post back in bit.

    Yes , the code will handle hundreds of thousands of lines if necessary.

  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA - Repeat Text until reach New Text

    My bad,
    Fixed.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-27-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA - Repeat Text until reach New Text

    Dave,

    Excellent, that handles larger line and Item numbers.

    It still however terminates before the end of the data set. Row 38, not Row 39 like it should.

    In a test on my larger spreadsheet, it terminates much earlier than expected. I've attached some of this data and your macro.

    Example Workbook 130628 2.xlsm

    Regards,

    Declan

  7. #7
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA - Repeat Text until reach New Text

    My bad again,

    You original code seems to have formatting in it, even on blanks cells, so my first code won't work. I have fixed that.

    See if this is what you need?

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-27-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: VBA - Repeat Text until reach New Text

    Dave,

    Brilliant.

    Thankyou,
    Declan

  9. #9
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA - Repeat Text until reach New Text

    No problem. Let me know if I can help you on anything else.

    Dave

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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