Consulting

Results 1 to 6 of 6

Thread: Solved: macro to remove data from list

  1. #1
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location

    Solved: macro to remove data from list

    see attached file
    Hi

    Need to amend the current macro to remove the data in worksheet"Sheet1" from row 851:903 columns B:F i.e remove guernsay from the data.

    The end result being the same table as worksheet 2 minus Guernsay from the list

    i have made one attempt but i feel something is missing from the following vba code...

    Sub Edit_Guernsey()

    Application.ScreenUpdating = False
    Cells.Find(What:="Guernsey", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

    Range("B851:F903").Select
    Rows("851:903").Select
    Selection.Delete Shift:=xlUp
    Range("B851").Select

    Application.ScreenUpdating = True

    End Sub

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub Edit_Guernsey()
    Const TARGET_COUNTRY As String = "Guernsey"
    Dim StartCell As Range
    Dim EndCell As Range
    Dim i As Long

    Application.ScreenUpdating = False

    With Worksheets("Sheet1")

    Set StartCell = .Cells.Find( _
    What:=TARGET_COUNTRY, _
    After:=.Range("A1"), _
    LookIn:=xlFormulas, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False, _
    SearchFormat:=False)

    Set EndCell = .Cells.Find( _
    What:="TECHNOLOGY", _
    After:=StartCell, _
    LookIn:=xlFormulas, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False, _
    SearchFormat:=False)

    i = EndCell.Row
    Do
    i = i + 1
    Loop Until Not .Cells(i, "B").Value Like "*.*"
    .Rows(StartCell.Row).Resize(i - StartCell.Row).Delete
    End With

    Application.ScreenUpdating = True

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    thanks xld......works prefectly...

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think that is the first time I have actually been able to help you :-)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    Quote Originally Posted by xld
    Loop Until Not .Cells(i, "B").Value Like "*.*"
    Bob!?

    What is the Like function doing?

    I've been thinking about it all day...Dosen't the Start find, and End find define the row parameters?

    Is it there in case the loop fails?

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No not quite, StartRow defines the start of the data it is true, but EndRow defines the start of the last block of data. We don#t know the name of the next country, and there is nothing special about the rows to allow us to pick it out. So what I did was to find the country in question (StartRow), then find the row with TECHNOLOGY after that row (EndRow), and then loop through until I found a row without a dot (.) in it, as TECHNOLOGY is followed by rows starting with 1., 2., etc. That is where Like kicks in, and I can loop until I get past those rows to the next country name.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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