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


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

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 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

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

How Do I Get Past A Delete, Cancel Button During A Macro Loop?

Aug 12, 2009

I would choose to select the delete button. I've created a new worksheet within a workbook, insert text and formatting, and copied to a specific place in the active worksheet. Everything works well except 1. there is a LOT of coding because I recorded the macro and 2. the delete message pops up for every files the macro manipulates. I have to click "delete" about 60 times throughout this macro and would love to be able to let it click its own delete button!

View 6 Replies View Related

RAG Formatting With Mutliple Conditions

Apr 11, 2008

I want to be get a response of Red, Amber or Green depending on:

Red if

A1 = blank and;
A2 = blank and;
A3 (which is a date) = greater than or equal to todays date


Amber if

A1 = blank and;
A2 = blank and;
A3 (which is a date) = todays date plus 1.


Green if

A1 = blank and;
A2 = blank and;
A3 (which is a date) = greater than todays date plus 1.

View 9 Replies View Related

Macro Loop Not Using All Rows

Nov 9, 2006

I've taken over a spreadsheet that has a macro in it. However it doesn't seen to function properly. The big issue with the Macro is that it is only running for the first 80 lines of data. I can't have a restricted range as the number of lines could increase/decrease each month depending on activity. I've attached the code.

Sub Macro1()
Dim strTemp As String
Dim intSpace As Integer
Dim intZero As Integer
Dim i As Integer
Dim strCat As String
Dim strZero As String
Dim intLoopCounter As Integer
Dim rw, this
intLoopCounter = 1
For Each rw In Worksheets(1).Cells(1, 1). CurrentRegion.Rows
this = rw.Cells(1, 1).Value ...................

View 8 Replies View Related

Macro To Delete If Set Of Multiple Rows Equals Another Set Of Rows

May 10, 2012

I need a macro that can look at multiple (say three) rows and delete those rows if they match another three rows in the worksheet.

For example:

1 0
3 1
5 7
4 4
6 5
8 3
1 8
5 2
3 9
6 5
8 3
1 8
7 5

If three rows are the same, then one set is deleted (it can be either bottom or top set). I would like to do this for rows 1-500 in the worksheet.

View 1 Replies View Related

Loop Through Rows Until Blank And Call Macro

Feb 16, 2007

I have a spreadsheet with a list of names from cell A5 to A? - can be as many as 130 names or as few as 20. I have to create individual spreadsheets with the persons name as part of the filename. I have 3 subroutines which work manually ( CreateFile, LookUp and NewWorkbookSave ) so that I can generate individual files for those users who require them. However I need to be able on occasions to create a full teams worth of files with one click - to this end I need to be able to loop through cells A5 - A whatever and call the Subroutine CreateFile - I enclose the code I have so far

Const Fname = "AON Ver 3,0.xls" 'insert filename here like "AON Ver 3,0.xls"
Const DirName = "\Ukplscs105central repositoryAOMTally SheetsTeam upload Tally sheets"
Const TeamName = "AON" ' insert team Name here like "AON"
Const FilePath = DirName & TeamName
Dim count As Integer

Sub CreateFile()
ChDir FilePath
Workbooks.Open Filename:=FilePath & Fname
Range("C3").Select
ActiveWindow.WindowState = xlMinimized
Call LookUp....................

View 5 Replies View Related

VBA Macro To Loop Text To Columns Through All Rows Of Data?

Apr 17, 2014

I am trying to get a macro to run in excel that takes a simple text to columns command in one line of data and runs the command on a loop through however many rows of data there happen to be.

I've attached two screenshots - one with what I've got now (Before.jpg) and what I'd like to have after the macro runs (After.jpg). The code below is what I used to get the first text to column breakout, which I can hopefully run on a loop to breakout anything in the DEPT column that contains a "/". It can ignore the rows that only have one department to begin with.

Selection.TextToColumns Destination:=Range("K2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="/", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True

Eventually I'll want to create another macro that transposes the breakout text back into the DEPT column and populates it with the corresponding data, but I figure I'll take things one step at a time.

Attached Images
Before.jpg‎
ter.jpg‎

View 10 Replies View Related

Loop Or Macro To Retrieve Rows Of Data From Other Worksheet

Dec 15, 2008

I need to query a master spreadsheet and pull out all the rows on it that have the same name as I have in cell A1 of my spreadsheet

e.g.

Myworkbook, sheetname = queries
Cell A1 = "ABC"

The Macro queries the "test Data" workbook (c:myfolder estdata.xls) "sheet x" and looks in column A for ABC, if it finds ABC it will copy the row and paste it into Myworkbook, sheetname = queries. There are often several rows of data that need to be copied that all have "ABC" in column A.

Also, in column B of the test data workbook, is a number, the highest value denotes the "version" of the data, the highest number is always the latest version of data that should be retrieved, e.g. if 9 the highest value in column B then all data that has ABC in column A and has 9 in column B should be retrieved, all other records should be ignored.

I guess this is a sort of a macro loop but not too sure how to do it.

View 10 Replies View Related

Delete Rows: Macro Skips Rows

Nov 5, 2006

Need to solve my problem in the thread "Type Mismatch Error Message". Now a new problem has come up in the same code, so - according to the rules - I've started a new thread. (This one is most likely due to my poor knowledge of VBA syntax).

Sub Delete_invalid_rows()
Dim i%, j%
Dim Nr%, valid As Boolean, BYPdata As Boolean
Dim ar1 As Variant
Dim ar2 As Variant
Dim ar3 As Variant
Dim ar4 As Variant
Nr = 20
ar1 = Array(11, 14, 19, _
20, 22, 25, 26, 27, 28, 29, _
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, _ .................

View 2 Replies View Related

Macro To Delete Last Two Rows

Mar 26, 2009

i wrote this macro and want to delete last two rows on active sheet this macro.

Sub deleteLast2Rows()
With ThisWorkbook.Worksheets(1)
Dim rowNum As Integer
Dim m As Range
rowNum = 2
Set m = .Range("A" & rowNum)
rowNum = rowNum - 2

EntireRow.Delete
End With
End Sub

View 2 Replies View Related

Delete Rows Macro ..

Oct 2, 2008

I have a huge spreadsheet that I want to be able to sort through and delete the unwanted rows. I want to do a search for anything in column C that equals 2225 including the next row after and delete the rest. Here is an example...

View 3 Replies View Related

Macro- To Delete Any Rows

May 22, 2007

I recorded this macro but I need it to delete any Rows that have the word "Normal" in column F

Sub Count()
'
' Count Macro
' Macro recorded 5/22/2007 by pricci
'

'
Sheets("Alarm Log").Select
Sheets("Alarm Log").Copy After:=Sheets(2)
Sheets("Alarm Log (2)").Select
Sheets("Alarm Log (2)").Name = "Count"
Cells.Select
Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

View 9 Replies View Related

Want To Delete Rows Using Macro

Sep 10, 2007

I want to delete the rows if in "Column L" value is "Yes".

View 9 Replies View Related

Macro To Delete Certain Rows ...

Dec 19, 2007

macro to delete certain rows from a sheet based on the value of a cell?

I'm tryin to get it so if the value in "F" is NOT 150, 151, 152, 153, 154, then i want that row deleted.

this should leave me with data that contains either 150 - 154 in column F.

View 9 Replies View Related

Macro To Delete The Rows

Jul 1, 2008

I have a table of data A2:H1000 (this gets longer every week). Within that data every so often i have a row which is blank from A:G, but has a value in H.

I want to create some code that checks the rows and if the cell A in the row is blank, to delete the entire row.

View 9 Replies View Related

Macro Delete The Rows

Sep 19, 2008

If I have a table (see below), is it possible to create a macro to delete rows that do not have defined data. In the example below, I would want to delete rows 4 through 7 as there is no date in Columns B through D.

A B C D
1 2008 100 200 300
2 2009 500 600 700
3 2010 800 900 1000
4 2010
5 2011
6 2012
7 2013

View 9 Replies View Related

For Each Loop To Delete Row W/ Value (Loop Backwards)

Aug 2, 2007

For Each loop can be instructed to loop starting the bottom of the range. I know that a For To Loop can handle looping from the bottom up,

Sub Filterout()
Dim c As Range
Dim rng As Range
Dim i As Long
Dim lrow As Long
Dim counter As Integer
lrow = Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Range("c2:c36")

For Each c In rng
If Left(c.Value, 1) "~~" Then
c.EntireRow.Delete
End If
Next c

View 9 Replies View Related

Delete Empty Rows Macro?

Apr 18, 2014

I have a formula that does exactly what I need , it fetches negative stocks from sheet 1 , but the formula places the data exactly on the same row where the negative is , thus there are a lot of in between data not required , Yes I can copy paste special values and remove blank rows , but the macro will do it faster

View 13 Replies View Related

Macro To Delete Rows Containing Certain Text

Jan 15, 2009

I have put together a macro that will delete rows (called DeleteUnwantedRows) in a spreadsheet that contain the phrases "no further action" and "not applicable" ... However the macro does not appear to be working.

View 2 Replies View Related

Macro To Delete Rows With A Condition

May 28, 2009

What I need is a macro to delete a row or rows for a specific range of cells (eg. E20 to E58) when the cells in that range column E is = blank. The cells in column E is formated with a currency sign $. Deleting the row should shift up all rows below. I need to run this macro manually. Excel 2002 SP3.

View 9 Replies View Related

Macro To Delete Rows And Sort

Sep 27, 2009

I have attached a worksheet to illustrate a "Before" (raw data) and "After" (desired results).

Each row contains data on a forex trade. The variables which must be assessed in each row are:

Currency Pair (e.g. GBP/USD).
Opening Time
Closing Time

What I need to do is delete many rows in the raw data because they reflect a condition I do not want in my analysis, which is having multiple open trades of a single currency pair during the same time period.

To perform my analysis I need to delete all trades (rows) which meet the above condition.

The worksheet provides examples, along with a rudimentary tool I've used to help me sort/delete rows manually.

Since I am looking at thousands of trades, a manual sort/delete is impractical. (my eyes don't like this kind of work!)

The rudimentary tool I've used in manual sorts/deletes is simply to have a column which returns a "1" if a trade opens before an older trade has closed. I do this by first sorting the data by (a) currency pair then (b) date opened. Then I must manually go through multiple iterations of deleting trades until there all of the "1's" have disappeared.

I'm hoping someone can show me a macro which might do this sorting/testing/deleting automatically, at least to the point where all I have to do is repeatedly press a "macro" button until there are no "1's"

View 8 Replies View Related







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