Results 1 to 5 of 5
  1. #1
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts
    I have an upcoming project to develop a database of acronyms and their definitions. The potential input data will be in a three column table. I need to delete every row that has an X in the third column. I may also need to delete, with a different macro, any row for which column two is empty. If someone can please help me with one, maybe I can figure out the other—as part of my very slow vba learning process.

    (Oh, how I still wish for the WordPerfect macro language. I could have figured this out ages ago. )


    Pam
    Pam Caswell

  2. #2
    5 Star Lounger
    Join Date
    Aug 2004
    Location
    Connecticut, USA
    Posts
    816
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here you go:

    Code:
    Sub DelX()
    Dim lRow As Long, i As Long
    lRow = Cells(Rows.Count, 3).End(xlUp).Row
    For i = lRow To 2 Step -1
    	If Cells(i, 3) = "X" Then
    	Cells(i, 3).EntireRow.Delete
    	End If
    Next
    
    End Sub

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    [quote name='mbarron' post='792062' date='04-Sep-2009 13:13']Here you go:

    Code:
    Sub DelX()
    Dim lRow As Long, i As Long
    lRow = Cells(Rows.Count, 3).End(xlUp).Row
    For i = lRow To 2 Step -1
    	If Cells(i, 3) = "X" Then
    	Cells(i, 3).EntireRow.Delete
    	End If
    Next
    
    End Sub
    [/quote]
    Hi mbarron,

    Your code might work for Excel, but not for Word ...

    Pam:
    Try something along the lines of:
    Code:
    Sub DelXRows()
    Dim oTbl As Table, oCel As Cell, oRng As Range, StrTxt As String
    StrTxt = "X"
    For Each oTbl In ActiveDocument.Tables
      For Each oCel In oTbl.Columns(3).Cells
    	Set oRng = oCel.Range
    	oRng.MoveEnd Unit:=wdCharacter, Count:=-1
    	If oRng.Text = StrTxt Then oRng.Rows(1).Delete
      Next
    Next
    End Sub
    For the later process, change "X" to "" and Columns(3) to Columns(2).
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts
    Paul and mbarron,

    Thank you so much. I knew you guys at Woody's would come through for me. I'll try it out as soon as I get to work this morning. I may have a use for one for Excel too.

    Many kind regards,
    Pam
    Pam Caswell

  5. #5
    5 Star Lounger
    Join Date
    Aug 2004
    Location
    Connecticut, USA
    Posts
    816
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oops, sorry about that. I didn't check the forum the post was in - I only read the subject.

Posting Permissions

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