Deleteng Lines

Eddie Wildon

Board Regular
Joined
Jul 29, 2005
Messages
83
Good morning everyone :)

I have a toughie that, after about 2 hours, I cannot seem to solve.

I have a worksheet spanning 54000 lines and need to weed out most of it to get at what I really want.

Several of the lines contain identical data but I cannot simply sort it because I need to maintain names above data.

Is there a script that I can use to look at each line, and if it contains certain text to delete the whole line, and then move on to the next line, all that way to the end of the report?

This will maintain the order that the data is in, while removeing unwanted lines. Any help on this would be appreciated.

JCA
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I just tried this and it sort of works. It worked opposite of what I thought it would. It deleted the empties in the sheet called "Original". I really wanted it to leave the original alone and delete in the sheet called "Holes Worksheet". This is how I changed the code.

Sub CopySheetAndDeleteCells()
Dim LastRow As Long
Dim Row As Long
Dim Column As Integer
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
On Error Resume Next
Sheets("Holes Worksheet").Delete
Application.DisplayAlerts = True
Sheets("Original").Copy Before:=Sheets("Original")
Sheets("Original (2)").Name = "Holes Worksheet"
Sheets("Holes Worksheet").Activate
For Column = 2 To 20 Step 3
LastRow = Cells(65536, Column).End(xlUp).Row
For Row = LastRow To 3 Step -1
If Cells(Row, Column).Value = 0 Then
Range(Cells(Row, Column - 1), Cells(Row, Column + 1)).Delete Shift:=xlUp
End If
Next Row
Next Column
For Column = 25 To 43 Step 3
LastRow = Cells(65536, Column).End(xlUp).Row
For Row = LastRow To 3 Step -1
If Cells(Row, Column).Value = 0 Then
Range(Cells(Row, Column - 1), Cells(Row, Column + 1)).Delete Shift:=xlUp
End If
Next Row
Next Column
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub


Thanks again for your help.

Ken
 
Upvote 0
Ken

Where have you placed your code? If you have it within the particular Sheet code, move it to a separate Module. To do this:
1. From the menu in the VBA window, choose Insert|Module
2. Double click the newly inserted Module and move the code to that Module.

See how that goes.
 
Upvote 0
Thanks! That makes sense. Sorry, it is my lack of knowledge when it comes to VBA. I had it inserted into the sheet that I want to keep.

Ken
 
Upvote 0
So, I finally was able to spend some time to actually try this. It works well. Now, when I get to work tomorrow, I'll have to go through and put this code in all my files. Thanks again for your help.

Ken
 
Upvote 0
Ken

Here's some other code that might be of interest though it would probably need to be adapted for your purposes.
Code:
Dim rng As Range

    Range("A1:I15").Replace What:="0", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
    Set rng = Range("A1:I15").SpecialCells(xlCellTypeBlanks)
    For Each rngArea In rng.Areas
        rngArea.Offset(, -1).Resize(, 3).Delete Shift:=xlUp
    Next
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top