VBA Code - Loop Through And Delete Rows

Oct 12, 2013

I use this code to delete some rows, how I would modify it to work in another spreadsheet where it would "Loop" through and delete rows that start with "User:Kellcyna" down to where the rolls start with "Numbers", and delete the rolls that start with "Total cost center" down to where the rolls start with "Numbers".

The data can contain up to 50000 rolls at times.

Sub Finally()
Application.ScreenUpdating = True
[a:a].AutoFilter Field:=1, Criteria1:="="
[a2:a65536].SpecialCells(xlVisible).EntireRow.Delete
If [a1] = "" Then [1:1].Delete
ActiveSheet.AutoFilterMode = False
[Code] ........

Here is a sample of the data I need the macro to work on. The rows I need deleted are the rows that are highlighted.

User: Kellcyna STANDARD HOURS BY COST CENTER Date: 09/29/2013 Time: 15:10:04 Page: 10

Comments:

Order Op Emp Post Work ctr Setup Unit Planned Earned Total Actual Actual Actual Total Total Orde C R

# Date SU Unit Plnd Stds Setup Run Tme Brd Tme Prod Run Time E

104527059 0010 00000000 09/25/2013 HSW01 0.000 0.4 HR 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 PP01

104523849 0010 00000000 09/25/2013 HSW01 0.000 0.2 HR 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 PP01

[Code] ...........

View 5 Replies


ADVERTISEMENT

Store Row Number Within Loop And Delete All Stored Rows After Loop?

Sep 11, 2013

I have working code that returns a row number within a for loop based on parameters I set.

Each time the for loop runs I would like to store this row number, then after the loop has finished, delete all stored rows.

Code:
for rowNum = 1 to x (some variable end row number which I already have worked out using End(xlUp).Row)
if x = y then
*storedRow = rowNum
end if
next rowNum
*

Lines with a * are the bits I can't work out. I've been trying to understand arrays by reading posts on what other people have done, but I can't fit (or fully understand) the reDims, or reDim preserves into my code. I've seen what appear to be quite complex ways involving uBounds and LBounds, but unfortunately I can't see how to use them.

All I want is to simply keep adding a row numbers to a variable, (i.e. row 2, 5, 20, 33, 120, etc) and then delete those specific rows.

View 4 Replies View Related

VBA Loop And Delete 15 Rows

Sep 10, 2013

I have output from mainframe that is copy/paste to an excel workbook. I need to have VBA loop and delete the 15 rows. This is mainframe output so it will always be 15 rows

Count
Campus
Name
Course
Start Date

1
336001
Student1
1
9/2/2003

[Code] ............

View 1 Replies View Related

Delete Rows, Formatting, Loop

May 15, 2009

1. Delete all data after row 51.
2. Find the average cost (column 4) and delete all rows where the cost is below average. Thus only retaining rows with an above average cost.
3. Then I want to conditionally format any number in column 6 which appears more than three times.
4. I want to loop this through all worksheets in my workbook.

View 9 Replies View Related

Loop Over Rows And Delete Row If Value Not In Table

Aug 11, 2006

I have two worksehets. The first worksheet contains data on products. The product code is in column A. My second sheet contains a list of product codes in column a. I want to delete all rows in worksheet 1 where the product code doesnt exist in the list in worksheet 2. Can someone provide a outline for a macro to loop over sheet one and look up the value in worksheet 2 and delete the row from worksheet 1?

View 3 Replies View Related

Delete Over 3000 Rows In Worksheet Without A Loop

Nov 15, 2008

I have anywhere from 3000 to 10000 rows to delete in a a number of worksheets, but would like to avoid using a loop as even with onscreen update turned to off like this:

View 3 Replies View Related

Macro To Delete Mutliple Rows On A Loop

May 20, 2009

I need to be able to run a macro that will find the word “report“ within a cell in column A. Once found it I then need it to delete that row, the row above and then the 9 rows underneath it. Once it has deleted that data I need it to then move to the next and so on.

It’s a report I have dropped into excel which repeats the page header. E.g the following is repeated constantly which I need to be deleted:

¬¬¬¬¬¬¬¬¬¬¬¬¬
Report: xxx
Company: xxx
Turnover By C
01/04/2008 To
**THIS REPORT
Customer: 0 T
¬¬¬¬¬¬¬¬¬¬¬¬¬
Account
Cust Num
¬¬¬¬¬¬¬¬¬¬¬¬¬

View 14 Replies View Related

Loop To Delete Rows If Middle Column Less Than 1

Nov 20, 2012

What I have is 3 columns, all containing numbers

What I want to do is delete a row if the middle column is less than 1.

However my loop seems to skip a row if the column data is like the below

a
b
c

1
1
1

1
0
1

1
0
1

1
1
1

1
0
1

End

Code:
Range("A2").Select
Do
If ActiveCell.Offset(0, 1) < 1 Then
Range(ActiveCell, ActiveCell.Offset(0, 2)).Select
Selection.Delete Shift:=xlUp
End If
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Value = "End"

View 5 Replies View Related

Delete 5 Rows With Loop Without Throwing Up Error?

Dec 31, 2012

I have some code that is working great except that it throws up an error on the last run through because it doesn't find any more rows to delete. I've tried "On Error GoTo" but it doesn't catch it. It seemed to work on my home computer which is running Excel 2010 but then on Excel 2007 I get the debug screen and I don't want that to show up for other users that I share the code with.

Sub DeleteHeaders()
Dim lastrow As Integer
lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row

[Code]....

View 3 Replies View Related

Find Data And Delete Remaining Rows (For Each Loop)

Apr 24, 2009

In the code below I find rows containing "$$ #" at the far left and process it.
For all the remaining rows I want to delete the entire row, my macro only deletes some rows. Obviously I am not grasping something about looping throught the rows to delete unwanted data.

View 2 Replies View Related

Code To Delete Rows Based On Status Code In Column

Jul 24, 2009

I'm trying to write a VBA script which will delete all rows in my Excel spreadsheet where Column I (which contains a status code) does not contain the word "Completed".

At the moment, I'm doing this the other way round: my script is able to search for entries in Column I which contain the status codes "Pending", "Awaiting Authorisation", "In Progress" etc and delete them. The idea is that when all those rows are deleted, I'll only be left with rows which have a status of "Completed". This works fine at the moment. However, the concern is that if a brand new status code is added to the data file, my script would be unable to pick it up and delete it. This is a small sample of the code I'm currently using (which deletes all the rows with statuses other than Completed):

View 4 Replies View Related

Insert Rows Within Loop Code

Apr 3, 2008

I have a requirement where I have to add a row with x columns using vba. this is the code I am using now

k = 17
prodetails = .GetFieldValue("Product Details")
sSeats = .GetFieldValue("Seats")
If isRecord Then
While isRecord
Sheets("Products").Rows(k).Insert Shift:=xlDown
Sheets("Products").Rows(k + 1).Insert Shift:=xlDown
Sheets("Products").Rows(k + 2).Insert Shift:=xlDown
ThisWorkbook.Sheets("Products"). Cells(k, Prod6Col) = prodetails
ThisWorkbook.Sheets("Products").Cells(k, Unit4Col) = sSeats
isRecord = .NextRecord()
Wend
End If

In this code I have declared Prod6Col and Unit4Col as constants. instead I need to use them as variables like in this modified code. However if i use this code, I get an object definition error.

k = 17
m = 20 (20th column)
l = 18 (18th column)
prodetails = .GetFieldValue("Product Details")
sSeats = .GetFieldValue("Seats")
If isRecord Then
While isRecord

View 4 Replies View Related

VBA Code To Delete Certain Rows

Jan 22, 2009

I have an excel file that i need to delete some empty rows in the file. it looks like this: I have to delete THE EMPTY ROW above each custom table, and leave everything else as it is.

empty row
custom table
data
data
data
empty row
custom table
data
data
data
data
empty row
custom table
data
data

View 11 Replies View Related

VBA Code To Delete Rows

Apr 30, 2014

I am looking for a vba code that will delete rows for me. have data in column E and I need the code to look for any cell that has the word "DELETE" in column E. When it finds the word "DELETE", I need it to delete the entire row. For instance if the first instance of this in cell E41120, then it should delete that entire row and look for the next instance to do the same.

I have seen codes out there to delete rows, but I can't get any of it to work for my situation.

View 7 Replies View Related

How To Delete Rows Using VBA Code

Jan 1, 2009

I have data in cells Starting from

B1= Quality, C1= Size, D1= Quantity, E1= Length, F1= Width, G1= Thickness

My data comprises from B2:D2000 ( I am exporting data from SQL Server) so the data is in the horrible conditions , having blanks cells in these three columns . Columns E , F and G are empty.

Can someone help me in cleaning these empty rows in the three columns on the following conditions

delete entire row if column B, C and D contains empty or blank cells or zero
delete entire row if any cells in Column C and D contains text values
delete the entire row if Cells in colums A contains the word Map

the data in the column C is in the following format( Length x Width x Thickness)
C2=78x36x4
C3=78.5x36.5x4.5
C4=7x4x3
C5=72x36x0.5
C6=72x36x19mm

Is it possible to get this data in the following form

E2=78,F2=36,G2=4
E3=78.5,F3=36.5,G3=4.5
E4=7,F4=4,G4=3
E5=72,F5=36,F6=0.5
E6=72,F6=36,G6=19mm

View 9 Replies View Related

Delete Rows Code

Mar 26, 2009

(excel 2007)

I am using the following piece of code, which I have copied and modified from another workbook in which it worked properly.


Option Explicit
Sub DeleteRows()

'Delete Unneeded Rows
Dim lUsedRangeRows As Long
Dim lRowCounter As Long

With ThisWorkbook.Sheets("Data")
lUsedRangeRows = .UsedRange.Rows.Count

For lRowCounter = lUsedRangeRows To 3 Step -1 'work from the bottom up
If DateValue(.Cells(lRowCounter, 5)) < DateValue(.Range("PayDate")) Then
.Cells(lRowCounter, 5).EntireRow.Delete
End If
Next lRowCounter
End With
End Sub

I receive a "Type Mismatch Error" on the If DateValue line (highlighted red). PayDate is a named range for cell A2 on the same page.

View 9 Replies View Related

Code To Delete All Empty Rows

May 20, 2014

I need a code that I can run that will delete all rows that have nothing in at the bottom of the sheet. What I mean is I will be printing a file and because rows have been deleted that had data in a lot of sheets are being printed and wasted. So what I need is a before close code or something that will actually make the last row with data in the last row!

View 2 Replies View Related

Code To Delete Empty Rows

May 7, 2007

I have a database and at times I have empty rows. I am trying to write code that looks at the database (it may change daily) and deletes the rows that are empty. The code I've written does NOT work:

Sub emptyrows()
Dim emptyrows As Object
Set emptyrows = Cells(65536, 255)
If Rows = "" Then
Selection.Delete Shift:=xlUp
End If
End Sub

View 9 Replies View Related

Code Won't Delete All Blank Rows

Sep 25, 2009

When I tried this code on excel at home it worked, but now i'm at work and it dosen't delete any rows at all!

Here's the ....

View 9 Replies View Related

Fastest Way To Delete Rows In Code

Aug 17, 2007

I have a bit of code that deletes row by row and takes a long time to process. I've seen people suggest deleting by range processes more quickly. How can I modify this to delete by range?

lngLastRow = Sheets(2).Range("A65536").End(xlUp).row
For lngRowCount = lngLastRow To 1 Step -1
If Application.WorksheetFunction. CountIf(Sheets(2).Range("A1:A" & lngRowCount), Sheets(2).Range("A" & lngRowCount)) > 1 Then
Sheets(2).Range("A" & lngRowCount).EntireRow.Delete
End If
Next

View 7 Replies View Related

Delete Duplicate Rows Code ...

Jun 4, 2008

I have trouble in deleting the duplicate rows. I have a code to find the duplicate values

Public Sub Unique_Proj() 'This is the first step which takes out the unique projects from the base data
'Call Work_Assignment
'this selects the unique projects in the sheet
Application. ScreenUpdating = False
Dim A, E, B(), n As Long
Sheets("Projects").Select
With ActiveSheet
A = . Range("g2", .Range("g" & Rows.Count).End(xlUp)).Value
Redim B(1 To UBound(A, 1), 1 To 1)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For Each E In A
If Not IsEmpty(E) And Not .exists(E) Then
n = n + 1: B(n, 1) = E: .Add E, Nothing
End If
Next
End With
Sheets("Unique Projects").Select
Range("G3:G" & Rows.Count).ClearContents
Range("G3").Resize(n).Value = B

End With
Application.ScreenUpdating = True
End Sub

However, this gives me a list of values in that perticular column only.

What I want is either delete the complete row which is duplicate OR select the entire range of values which are unique (based on the column searched) and paste it in a new sheet. The second option is more better for me.

View 7 Replies View Related

VBA Code To Delete Rows If Specific Value Is Not Present?

Aug 6, 2014

I'm trying to write a macro to update a report including deleting all rows that do not contain a specific value of TP in column K. Below is one of the examples.

[Code] .....

View 3 Replies View Related

Which Are The Variables In The Code, Delete All The Rows Which Have Data In?

Oct 28, 2008

This vba code will delete all the rows which have data in. At present it starts on A2 (so doesnt delete anything above A2. Which part of the code in red would I need to change for it to be A3 and which would I need to change for it to be B3.

View 5 Replies View Related

Code To Delete Rows Based On Condition

Apr 24, 2009

I have an Excel spreadsheet that is given to me weekly, but I'd like to remove repetitive and empty rows before presenting it to someone. It is set up like this:

Row 1, A1, contains the word Project.
Row 2 is blank
Row 3 is blank
Row 4 is blank
Row 5, A5, contains the word Organization.
Row 6 is blank
Row 7, A7, contains a 6-digit number starting with 3.
Row 8 is blank

(all of the above starts over again (loops) approximately 30 times)
The final row contains the phrase "Grand Total"

*Row 5 is repetitive and is not required. I'd like to delete it.

I have too many empty columns. Getting rid of them (and Row 5) would greatly shorten my spreadsheet.
I am aiming for:
Project
301111

Project
301112

Project
301110
(Repeat until finished)

Grand Total:

View 4 Replies View Related

Code To Delete Rows After Selected Cell

Sep 24, 2011

I've got a sheet that I build from a weekly sheet. I can have 30 to 60 rows, but I always have 10 to 20 rows left over with data in column C, none in A, my last code is "Range("A1").End(xlDown).Offset(1, 0).Select" which takes me to the last cell in column A. Any code that I can then delete say 20 rows after that? I tried one code, but it wanted to delete everything below the cell selected which ran & ran.

"-" are blanks. Range moves the selected cell to A4. I want to delete row selected + 19 more.

-|A|B|C|D
1|Y|2|9|J|
2|R|1|8|N|
3|G|4|7|N|
4|-|-|L|-|
5|-|-|L|-|

View 9 Replies View Related

VBA Code To Delete Duplicate Rows In Workbook

Sep 8, 2013

I have a worksheet populated with data. I have sorted the data and have dupulicate values in column B,C,D up to H.
I have put in a formula to give me a 1 value in column A where there are duplicates. Is there a way to write a VBA code that will Delete all the rows that have a 1 in column A.

View 4 Replies View Related

VB Code To Compare/delete Rows Of Data

Feb 4, 2007

VB code to carry out the following task?

Look at name in cell BC2, check the name in cell BA2 and if is the same delete the name in BA2 and BC2.

If is different then leave both cells as they are and move onto checking BC3 against BA3
carry this loop thru BC2 : BC40

View 9 Replies View Related

VBA- Code That Will Delete Blank Rows Between Data

Apr 1, 2009

a code that will delete blank rows between data, below is sample of my data, the header row is 8

From this ....

View 9 Replies View Related

Code To Delete Rows - Reset Running Total

Dec 6, 2012

I have a sheet with several thousand rows. I want code that will do this:

- After finding a "D:" in column A (contained in the cell but will be at a different place each row), start a running total of values in column B.
- When finding "F0" in column A...
--if the running total of values for rows that have "D:" equals the value in column B with the "F0", delete the "D:" rows
--if the running total doesn't match, reset the running total and search for the next "D:"
- Repeat for all rows.

View 1 Replies View Related

Total Data- Having A VB Code To Delete Empty Rows

Mar 7, 2007

The spreadsheet I am working in has $ which I need to total. The information, or rows, can vary from day to day so there is no static place to have a cell with an @sum. Management wants me to add a pretty line that says

'Total' in one cell and the $ next to it. I have about 30 sheets with columns to total. Yuck, takes forever.

How do all of you total if you don't know the last row? At the top?

I thought it might work to put an @Sum in the last row of the spreadsheet, in the column

I need to total, and having a VB code to delete empty rows. That would be automatic.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved