Results 1 to 12 of 12

Better way than using a do until loop?

Threaded View

  1. #1
    Registered User
    Join Date
    03-08-2012
    Location
    Notts
    MS-Off Ver
    Excel 2010
    Posts
    71

    Question Better way than using a do until loop?

    Good Morning,

    In my excel sheet I have 2 columns of data, (previously exported from ms project earlier on in the macro) that I want to filter data out of.
    At the moment, I have tried to create a loop which searches column B starting at "B4" until it has either; found the term "Engineering" or comes to the end of the list without finding it, at which point the loop stops.
    If the term "Engineering" is found, the data in the cell 1 to the right is copied into cell "C20".

    Here is the code i put together below:

    Sub Filter()
    
        Range("B4").Select
    Do Until Selection.Value = ""
    If Selection.Value = "Engineering" Then
       Range("C20").Value = Selection.Offset(0, 1).Value
    Else
            Selection.Offset(1, 0).Select
    End If
    Loop
    
    End Sub
    At the moment the code just keeps looping or gets stuck on the term engineering if it is found.
    Can anyone improve upon this code or post/suggest an alternative to using such a loop? If done differently, the range to be checked/looped between is ("B4:B14").

    Any help greatly appreciated.
    Kind regards
    Last edited by arlu1201; 09-05-2012 at 06:13 AM. Reason: Replaced quote tags with code tags.

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