Macro To Delete Variable Rows

Jan 4, 2012

I am creating a macro to tidy up a large data sheet. it is a list of products as follows:

Heading1Code; Heading2date; etc
12
12
12

13
13

14

15
15
15

The blanks beneath each series of products need to be deleted but they are variable and a macro that i write is not flexible enough to remove a variable number of blank rows beneath a variable number of each product.

View 9 Replies


ADVERTISEMENT

Delete Rows Not Matching Date Variable

Mar 10, 2008

I have a need to call a sheet from another sheet, copy two pages from the newly opened, existing sheet to a new workbook, search one sheet of the new workbook for any entries that don't contain a variable I specify, which is the first four digits of the field, and delete them. The sheets represent a daily view of jobs (identified by the "RptDate" variable) and an entire monthly list of jobs, which I want to delete all of them not from the date specified in the variable "RptDate". The fields in column A contain the date in "mmdd" format as the first four digits, and I have that specified in the "B1" celll of the originating workbook.

I found some code in this link Search Column Delete Row If Value Found that looked good. I had to modify it since I needed to search for a variable (RptDate) and needed to search column A and start on row 8 of that column. My current code looks like this:

Sub Macro1()

Dim RptDate As String
Dim RptMonth As String
Dim iLastRow As Long
Dim i As Long
RptDate = Range("B1").Text
RptMonth = Range("B2").Text
Workbooks.Open Filename:=(RptMonth)
Sheets( Array(RptDate, "Total Database")).Copy
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 8 Step -1
If Left(Cells(i, "A").Value, 4) <> RptDate Then
Rows(i).Delete
End If
Next i
End Sub

It works fine right up to the "Rows(i).Delete" line. It errors out with a "run-time error 1004, delete method of range class failed" and highlights the above line. I know the fields I'm pulling the variables from are working right since it opens the correct workbook off of one of them.

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

Variable Number Of Rows In Macro

Nov 2, 2011

I'm trying to write a macro with a variable number or rows depending on the total number of rows the workbook has.

I tried like this:

Code:
Sub provaanova()
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range(("$J$2:$J$") & Range("J" & Rows.Count).End(xlUp).Row) _
, ActiveSheet.Range(("$J$2:$J$") & Range("J" & Rows.Count).End(xlUp).Row), False, False, 99, "ANOVA", False, _
False, False, False, , False
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
End Sub

and:

Code:

Sub Provaregress()
r = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("$J$2:$J$r") _
, ActiveSheet.Range("$K$2:$M$r"), False, False, 99, "ANOVA", False, _
False, False, False, , False
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
End Sub

But it gives me an error. The only way i was able to do it without error was:

Code:
Sub Provaregress()
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("$J$2:$J$53968") _
, ActiveSheet.Range("$K$2:$M$53968"), False, False, 99, "ANOVA", False, _
False, False, False, , False
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
End Sub

But as u can see it has a fixed number of rows. ( I need variable number of rows detected on column J, and then run regression with K,L,M as depending variables).

View 5 Replies View Related

Printing Variable Rows With A Macro

Feb 14, 2007

I export data from another programme into excel and have written a macro to move and format this. The number of rows of data exported will be different each time. I need to be able to print this data and want to add it to the macro. I have learnt to use this code to select this data working from the last used cell to the top

Range("a1:d1", Range("a65536:d65536").End(xlUp)).Select

Using the macro recorder for printing one of my exports I got this code

Range("A1:D53").Select
Range("D53").Activate
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup.......................

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

Concatenation Macro For Variable Rows And Columns?

Apr 12, 2012

Our company gets excel spreedsheets with UPC numbers. The numbers are divided in parts or columns. Sometimes it's in 2 columns; sometimes in 3; and sometimes in 4 like this:

A_____B_____C____D
023__14444__779__9
023__14442__789__7

I'd like to be able to concatenate the digits and have the entire UPC number appear in a blank column to the immediate right and go straight down the line and calculate them all. I figured out how to do this with separate macros for 2, 3, and 4 digits or columns.

Sub Combine_2_Part_UPC()
Do While ActiveCell ""
ActiveCell.Offset(0, 1).FormulaR1C1 = ActiveCell.Offset(0, -1) & ActiveCell.Offset(0, 0)
ActiveCell.Offset(1, 0).Select
Loop
End Sub

Is there a way I could do this with just one macro, by maybe selecting the digits of the first UPC number in the first row of the data to cue the macro in as to how many columns to process?

(The UPCs are in the midst of a lol of other data like product cost, so a macro probably wouldn't be able to figure out how many to calculate on its own.)

View 2 Replies View Related

Macro To Copy And Paste Into Another Sheet At Variable Rows?

Nov 14, 2012

Sheet 2 has 3 cells with values:

C14, C15, C16

I need VB code to:

copy the values in those cells

Return to Sheet 1, let the user click a cell in any row in Colum F, then Paste them (Special, Values and Transpose)

View 4 Replies View Related

Copy And Paste Macro - Variable Number Of Rows

Jan 13, 2009

I am working on a macro where I am creating a formula to string together some text columns and then copy the formula down the entire column. The data source I will be performing this on will change in number of rows period to period. The data would be in columns A,B & C and the formula is in D. The formula in D is stringing together the data in AB & C and then I want to copy and paste that formula down to the bottom of all of the data. What would the code be for the copy and paste with variable rows?

View 9 Replies View Related

Macro Code To Add Sum Formula/Function, With Variable Rows, To Cell

May 29, 2008

I am having to copy and paste rows of data into a new worksheet where the rows sizes change and I am wanting to add a new row at the end of the pasted rows but with the sumation formula to add the relevant column

e.g copy range B14:AA17 with in this case columns E to AA holding the numerical values. Therefore I wish in cell E18 to sum the value of E14:E17 and so on ending with cell AA18 holding the sum of AA14:AA17

As these vary I have all relevant variables, Range to add sumation values to eg E18:AA18
Start Cell E14 and so on.

I tried adding "=SUM(x:d)" where x and d are vars relating the the column cell required eg x = E14 and d = E17

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

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

Macro To Delete Rows Containing All Zeros

Oct 19, 2009

I have a daily worksheet that will always have 9 columns. The end of the data contains some rows that contain all zeros. The number of rows will vary from day to day. Is there a way to specify that "if the cells in columns A:I contain a zero, delete the entire row"?

View 4 Replies View Related

Macro To Delete Rows With Same Data

Nov 18, 2005

In the sample below I need a macro that will delete the entire rows
where the data is repeated in a given column---that is, that it would delete
the repeat ones, leaving one of them. In this example, in the first set, all
that should be left are two rows which contain ME22N and MR8M in column E.
ME22N is repeated two more times and those rows need to be deleted.

If I could get a macro that would ask for the column to operate in, that would be
great for other spreadsheets where it would not necessarily be column E.

ABC DE
MACLEOLLynn MacLeodP0040104ME22N
MACLEOLLynn MacLeodP0040104ME22N
MACLEOLLynn MacLeodP0040104ME22N
MACLEOLLynn MacLeodP0040104MR8M

MACLEOLLynn MacLeodP0050006MB0A
MACLEOLLynn MacLeodP0050006MB0A
MACLEOLLynn MacLeodP0050006MB0A
MACLEOLLynn MacLeodP0050006ME21N
MACLEOLLynn MacLeodP0050006ME21N
MACLEOLLynn MacLeodP0050006ME21N.............

View 12 Replies View Related

Macro To Delete Rows With Data

May 6, 2003

I need a macro to delete rows that contain specific data in column A. For example, in the attached spreadsheet below,I need the macro to look for data in rows A1 - A7 (highlighted in yellow) and then delete the rows. The same data occurrs several times in the spreadsheet. The macro will need to delete all rows where this data occurs in column A.

Microsoft Excel - Book2___Running: xl2002 XP :
OS = Windows XP (F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)boutD9=
ABCDEFGHI1

[Code] .......

View 9 Replies View Related

Delete Rows And Column Macro

Aug 1, 2011

I want to create a Macro to be used on the Active Sheet that FIRST deletes all the rows that contain the following values in Column E. Here are the values contained in Column E that will result in deleting the whole row: PT, JK, BH.

Here is a data sample, the real data will have thousands of rows:

ROW 1 COLUMN E ROW 2 Work Code ROW 3 BN ROW 4 KL ROW 5 PT ROW 6 JK
ROW 7 AL ROW 8 BH ROW 9 PT ROW 10 JK ROW 11 TU ROW 12 PT

Second, I would like the Macro to DELETE the ENTIRE Column E Not just the values in Column E.

View 5 Replies View Related

Macro To Delete Blank Rows

Nov 13, 2012

I would like VBA code to delete all rows where there are blanks in Col B

View 2 Replies View Related

Macro To Delete Rows Outside Of A Range

Nov 20, 2012

I have a large workseet that I want to Delete all rows where value in column Q is > 9.99 and < 60.00. So the only rows left would be where column Q value is < 9.99 and > 59.99. (deleting out the middle amounts) I think this might be a nested If stmt but have not figured it out so I'm not sure if there is another way.

View 4 Replies View Related

Run Macro To Delete All Rows (except For First 2) In A Table?

Apr 30, 2013

I need to run a macro to delete all the rows (except for the first 2) in a table. The table is named "Table1". The problem is the tables size is always different. Is there a way in VBA where I can resize the table to the original size?

View 2 Replies View Related

Macro To Delete Selected Rows

Feb 13, 2007

I can use Find to find all all my rows where there is an "X" in a cell, and delete all the rows found that way (even if they are separated by other rows) in one fell swoop -MANUALLY. I use Find after having limited the area to be searched with a named array (so other "X's" don't get involved).

But when I record a macro with all the same moves, NONE of the Find code appears in the macro AT ALL....just the delete command. Hello? Relative reference (on the record macro toolbar) seems to have no impact.

So....the mission here is to delete entire rows wherever an "X" has been entered in a certain cell to mark the row for deletion...and those X's get there either through a DV list OR by a cell below the DV copying down the X from the DV cell above.

This is so because sometimes rows are "sub" to the one above, and if the one above is marked for deletion, then so must be the rows sub to it.

I have found this seemingly simple for...next loop here on the board:

For a = 1 To 50
If Cells(a, 17) = "x" Then
Rows(a).Select
Selection.EntireRow.Delete
Next a

But the debugger reports a "next" without a "for" which is obviously there in dark blue as I suppose it should be.

If I could make this puppy work, I would sooner have it start from A2 and then go down from there to the last row -wherever that happens to be.

View 9 Replies View Related

Macro To Delete Rows On A Criteria

Aug 8, 2007

I have macro code to hide rows based on a certain critera but I don't know how to adapt the code to delete the rows. Basically it checks a column and for every row

View 9 Replies View Related







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