Prev: attachments
Next: Auto jump to the next field
From: JeffG on 23 Feb 2010 09:02 I have a table that has a number of bookmarks in the first column. Depending on a condition, I want to delete all the rows between 2 of the bookmarks but not the row that the bookmark is on. It seems simple but I can't find the magic words to make it happen. Any help would be greatly appreciated.
From: Pesach Shelnitz on 23 Feb 2010 11:50 Hi Jeff, See if the following macro has the magic that you are seeking. Sub DeleteRowsBetweenBookmarks() Dim BkmName1 As String Dim BkmName2 As String Dim MyRange As Range Dim Pos1 As Long Dim Pos2 As Long With ActiveDocument Set MyRange = .Range BkmName1 = InputBox("Type the name of the first bookmark.") If .Bookmarks.Exists(BkmName1) = False Then MsgBox "The first bookmark specified does not exist." GoTo ErrorHandler Else If .Bookmarks(BkmName1).Range.Tables.Count > 0 Then Pos1 = .Bookmarks(BkmName1).Range.Rows(1).Range.End Else MsgBox BkmName1 & " is not in a table." GoTo ErrorHandler End If End If BkmName2 = InputBox("Type the name of the second bookmark.") If .Bookmarks.Exists(BkmName2) = False Then MsgBox "The second bookmark specified does not exist." GoTo ErrorHandler Else If .Bookmarks(BkmName2).Range.Tables.Count > 0 Then Pos2 = .Bookmarks(BkmName2).Range.Rows(1).Range.start Else MsgBox BkmName2 & " is not in a table." GoTo ErrorHandler End If End If End With If Pos2 < Pos1 Then MsgBox "There are no rows to delete" GoTo ErrorHandler End If MyRange.start = Pos1 MyRange.End = Pos2 MyRange.Rows.Delete ErrorHandler: Set MyRange = Nothing End Sub -- Hope this helps, Pesach Shelnitz My Web site: http://makeofficework.com "JeffG" wrote: > I have a table that has a number of bookmarks in the first column. Depending > on a condition, I want to delete all the rows between 2 of the bookmarks but > not the row that the bookmark is on. It seems simple but I can't find the > magic words to make it happen. > > Any help would be greatly appreciated. >
From: JeffG on 24 Feb 2010 07:41 Thank you for your response. The code worked beautifully. "Pesach Shelnitz" wrote: > Hi Jeff, > > See if the following macro has the magic that you are seeking. > > Sub DeleteRowsBetweenBookmarks() > Dim BkmName1 As String > Dim BkmName2 As String > Dim MyRange As Range > Dim Pos1 As Long > Dim Pos2 As Long > > With ActiveDocument > Set MyRange = .Range > BkmName1 = InputBox("Type the name of the first bookmark.") > If .Bookmarks.Exists(BkmName1) = False Then > MsgBox "The first bookmark specified does not exist." > GoTo ErrorHandler > Else > If .Bookmarks(BkmName1).Range.Tables.Count > 0 Then > Pos1 = .Bookmarks(BkmName1).Range.Rows(1).Range.End > Else > MsgBox BkmName1 & " is not in a table." > GoTo ErrorHandler > End If > End If > BkmName2 = InputBox("Type the name of the second bookmark.") > If .Bookmarks.Exists(BkmName2) = False Then > MsgBox "The second bookmark specified does not exist." > GoTo ErrorHandler > Else > If .Bookmarks(BkmName2).Range.Tables.Count > 0 Then > Pos2 = .Bookmarks(BkmName2).Range.Rows(1).Range.start > Else > MsgBox BkmName2 & " is not in a table." > GoTo ErrorHandler > End If > End If > End With > If Pos2 < Pos1 Then > MsgBox "There are no rows to delete" > GoTo ErrorHandler > End If > MyRange.start = Pos1 > MyRange.End = Pos2 > MyRange.Rows.Delete > ErrorHandler: > Set MyRange = Nothing > End Sub > > -- > Hope this helps, > Pesach Shelnitz > My Web site: http://makeofficework.com > > > "JeffG" wrote: > > > I have a table that has a number of bookmarks in the first column. Depending > > on a condition, I want to delete all the rows between 2 of the bookmarks but > > not the row that the bookmark is on. It seems simple but I can't find the > > magic words to make it happen. > > > > Any help would be greatly appreciated. > >
|
Pages: 1 Prev: attachments Next: Auto jump to the next field |