+ Reply to Thread
Results 1 to 5 of 5

Code to Loop and Delete Relevant String

  1. #1
    Registered User
    Join Date
    01-27-2015
    Location
    Colorado
    MS-Off Ver
    2013
    Posts
    2

    Code to Loop and Delete Relevant String

    Hi there,

    I'm trying to edit a macro I originally recorded that ended up being about 3000 lines, about 2000 of which are "ActiveWindow.ScrollColumn = x". These "ActiveWindow.ScrollColumn = x" are the lines I'm trying to remove to ultimately clean up the original script. So, I copied and pasted the lines of code into an Excel spreadsheet in an effort to write some more code to loop through these cells and delete the scrolling lines.

    My sub looks like this:

    ''Deleting Scrolls Script
    Sub deleteScrolls()
    Dim i As Integer
    For i = 1 To Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
    If Cells(i, 1).Value Like "ActiveWindow.ScrollColumn" Then
    Rows(ActiveCell.Row).Select
    Selection.Delete Shift:=xlUp
    End If
    Next i
    End Sub

    I also tried a slightly different version of the code:

    'test 2
    Sub deleteScrolls()
    Dim i As Integer
    For i = 1 To Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
    If ActiveCell.Value Like "*ActiveWindow.ScrollColumn*" Then
    Rows(ActiveCell.Row).Select
    Selection.Delete Shift:=xlUp
    End If
    Next i
    End Sub

    So I'm trying to loop through and delete any lines that have the value of the ActiveWindow.ScrollColumn using the Like command. I'm assuming this part is where the code is falling short.

    I have attached a screenshot of the Excel doc with an example of the lines I'm trying to delete.

    Any help would be greatly appreciated.
    Attached Images Attached Images

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Code to Loop and Delete Relevant String

    Hi snaggle,

    Welcome to the Forum!

    Maybe:

    Please Login or Register  to view this content.
    BTW - Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Code to Loop and Delete Relevant String

    Try this code
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Code to Loop and Delete Relevant String

    Hi Snaggle,

    Thanks for the rep!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  5. #5
    Registered User
    Join Date
    01-27-2015
    Location
    Colorado
    MS-Off Ver
    2013
    Posts
    2

    Re: Code to Loop and Delete Relevant String

    Awesome, all taken care of. Thanks for the help and timely response!

+ 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. VBA Do while loop to capture relevant data from a master sheet?
    By monkeypants in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-12-2014, 11:42 AM
  2. Excel Web scraping loop and filling the relevant cells
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 12-20-2012, 07:33 AM
  3. [SOLVED] VB Code To Delete Rows between 2 flags on loop
    By shauncol3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-08-2012, 07:46 PM
  4. excel vba macro loop using save and delete code
    By she_armario in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-05-2012, 03:04 AM
  5. vba code to delete rows with string of text found
    By yankeekid86 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2011, 07:08 PM
  6. vba code to delete rows with string of text found
    By yankeekid86 in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 09-13-2011, 11:50 PM
  7. [SOLVED] Adding a loop to conditional delete code
    By maw via OfficeKB.com in forum Excel - New Users/Basics
    Replies: 21
    Last Post: 08-15-2006, 11:15 AM

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