If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Entire row select and delete !

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-12-08, 17:03
Yikkes Yikkes is offline
Registered User
 
Join Date: Mar 2008
Posts: 7
Entire row select and delete !

Hi,

I've got a large Excel file that I need to keep 1 record in 7.

So I'll run thru it with a Rows = 1 to 100000 loop.

I'll select an entire row if one cell meets a certain criteria and delete the entire row.

What's the command for selecting entire rows and is it possible to delete such selections ?

Please the commands.

I thought it was

EntireRow.select
selection.delete

but that doesn't compile.


I'd like the row to dissappear so I might use a shift 1up command.

All ideas welcome.

Thanks,

H.
Reply With Quote
  #2 (permalink)  
Old 03-12-08, 17:30
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
I'm not strong in Excel VBA, but when I need to figure out how to do something, recording a macro and viewing the resulting code usually works. Here's the code from my deleting row 11:

Rows("11:11").Select
Selection.Delete Shift:=xlUp

See if that helps.
__________________
Paul
Reply With Quote
  #3 (permalink)  
Old 03-12-08, 19:38
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
Howdy. Brett (at VBAExpress) provided a complete solution for this:

Code:
Sub KillRows() 
     
    Dim MyRange As Range, DelRange As Range, C As Range 
    Dim MatchString As String, SearchColumn As String, ActiveColumn As String 
    Dim FirstAddress As String, NullCheck As String 
    Dim AC 
     
     'Extract active column as text
    AC = Split(ActiveCell.EntireColumn.Address(, False), ":") 
    ActiveColumn = AC(0) 
     
    SearchColumn = InputBox("Enter Search Column - press Cancel to exit sub", "Row Delete Code", ActiveColumn) 
     
    On Error Resume Next 
    Set MyRange = Columns(SearchColumn) 
    On Error Goto 0 
     
     'If an invalid range is entered then exit
    If MyRange Is Nothing Then Exit Sub 
     
    MatchString = InputBox("Enter Search string", "Row Delete Code", ActiveCell.Value) 
    If MatchString = "" Then 
        NullCheck = InputBox("Do you really want to delete rows with empty cells?" & vbNewLine & vbNewLine & _ 
        "Type Yes to do so, else code will exit", "Caution", "No") 
        If NullCheck <> "Yes" Then Exit Sub 
    End If 
     
    Application.ScreenUpdating = False 
     
     'to match the WHOLE text string
    Set C = MyRange.Find(What:=MatchString, After:=MyRange.Cells(1), LookIn:=xlValues, Lookat:=xlWhole) 
     'to match a PARTIAL text string use this line
     'Set C = MyRange.Find(What:=MatchString, After:=MyRange.Cells(1), LookIn:=xlValues, Lookat:=xlpart)
     'to match the case and of a WHOLE text string
     'Set C = MyRange.Find(What:=MatchString, After:=MyRange.Cells(1), LookIn:=xlValues, Lookat:=xlWhole, MatchCase:=True)
     
    If Not C Is Nothing Then 
        Set DelRange = C 
        FirstAddress = C.Address 
        Do 
            Set C = MyRange.FindNext(C) 
            Set DelRange = Union(DelRange, C) 
        Loop While FirstAddress <> C.Address 
    End If 
     
     'If there are valid matches then delete the rows
    If Not DelRange Is Nothing Then DelRange.EntireRow.Delete 
     
    Application.ScreenUpdating = True 
     
End Sub
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On