VBA To Remove / Delete Based Off Single Criteria Without Loop

Apr 23, 2013

I'm okay with Excel, but I'm just getting into utilizing VBA and I've been searching high and low for a simple VBA code that will remove/delete rows based off a single criteria without loop as there are over 40,000 rows. I tried a couple that I found onilne, and adapting them to my criteria range, but no luck. (All the ones that I found that work use loop and it takes about 15 mins to run through the entire spreadsheet)

I would like to maintain my first row as it's my headers. My single criteria is to remove all rows that have "NO" in column D.

View 9 Replies


ADVERTISEMENT

Run / Loop Through Cells And Delete Based On Criteria

Mar 4, 2014

I am trying to run (or loop) through a column of cells, and if cell contains certain text (e.g. ALPHA, BRAVO, CHARLIE) and delete the row if found.

My macro as I run it:

Sub DATA_TEXT ()

'Number of cells to loop through (I am unsure how the .xlend works!)
For i = 1 to 2500

'If function defining the criteria.
If cells (1, i) = "ALPHA" OR "BRAVO" OR "CHARLIE" Then

[Code] .....

View 4 Replies View Related

For Each Loop To Count Text In A Cell With Multiple Criteria In Single Column

Dec 19, 2011

Is there any method to speed up a for each loop to count text in a cell with multiple criterias in a single column. This is on example:

Code:
For each rr in r

If rr = "a" And rr.Font.Strikethrough = False Or rr = "B" _
And rr.Font.Strikethrough = False Then
a = a + 1

end if
next

View 1 Replies View Related

VBA Loop - Remove Single Character From Cell String Then Calculate New Value In Cell

Mar 1, 2012

I have a string of text in cell A2. In cell B2 of my spreadsheet is a formula that calculates a number based on the text string in cell A2.

I want to write a VBA loop that removes a single character from the cell A2 string, then calculate the new value in cell B2. I want this loop to continue until the value in B2 falls below a set value (in this case 60).

My code so far
Sub trim_text()
Dim mytext As String
Dim myanswer As Integer
mytext = Range("A2")
myanswer = Range("B2")
Do While myanswer > 60
mytext = (Right(mytext, Len(mytext) - 1))
Loop
End Sub

This obviously does not work. In my excel table I have a formula in cell B2 to calculate "myanswer" will this work, or does that code have to be placed into the VBA code?

View 3 Replies View Related

Loop To Delete Row When Criteria Is Met

Jul 13, 2006

I am using this to delete rows from my excel sheet. I basicaly start my script by placing xxx in cell B2000. I want to optimize my code and maybe some how tell excel do until last cell. I am playing with:

"Do Until lLastRow = Range("B" & Rows.Count).End(xlUp).Row"
But not shure how to procede with this.

Range("B1").Select
Do Until ActiveCell = "xxx"
If ActiveCell = "Ticket" Then
ActiveCell.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Loop

View 2 Replies View Related

Summing Based On Single Criteria

Aug 10, 2006

I am not sure my title is accurate so I will explain what I am trying to do. I would like to total the numbers from each row which has "Monthly Totals" in column A. There are currently only two of these but there will be more added over the year. Rather then have to edit the formula to include the new cell I want added to the total, is there a way to create a formula which will automatically scan Column A for "Monthly Total" then add the cell from that row to the running total at the top? Basically, If any cell in Column A has "Monthly Total" add the cell from column B (from the same row) to the running total in cell B1. This way I could add as many "Monthly Totals" as needed and I wouldn't have to edit the formula in cell B1.

View 7 Replies View Related

Delete Row Based On Cell Value - Loop

Oct 22, 2012

I have this setup successfully for the deletion of columns and have modified the below to apply to rows, however, I am not seeing the results I expect (or actually anything).

Code:
Sub Analytic_RemoveNA()

'Remove NA
Dim j As Long

For j = 35 To 4 Step -1 'Rows 35 to 4
If Cells(9, j).Value = "NA" Then Rows(j).Delete
Next j
End Sub

I have a data set that spans from B4:I32. If column I has "NA" in any row within that dataset, I want to delete the row.

View 3 Replies View Related

Delete Row And Loop Based On Condition

Jan 9, 2007

i have a set of data as below and wish to delete ENTIRE ROW if cell is the same but keep the first entry when code comes to it..ie in the data set below excel would keep first row and delete 2nd,3rd,5th, 6,7,8 and then go to next unique identifier which would be AU0000LIFHB3 this would not be deleted as it is unique the would proceed to AU300GPTC011. this process would then stop when no data was available

AU300AUS1019
AU300AUS1019
AU300AUS1019
AU0000LIFHB3
AU300AUS1019
AU300AUS1019
AU300AUS1019
AU300AUS1019
AU300AUS1050
AU300GPTC011
AU300GPTC011
AU300GPTC011
AU300GPTC011
AU300INTE018
AU0000LIFHB3
0
AU300SUNQ027

View 4 Replies View Related

VBA Delete Entire Rows Based On The Value Of Single Cell

Jun 10, 2009

I know it can delete entire rows based on the value of single cell, I just don't know how to do it. So what I need is a macro that will delete an entire row if the value in a particular column = 0.

More details: ....

View 9 Replies View Related

Display Unique Cells Based On Single Criteria

Mar 17, 2014

See attached file, basically need a formula that will give me the unique resources for each location. I know a pivot table would be easier but i need a formula for my model to work.

View 6 Replies View Related

Copy Rows Based On Criteria In Single Column

Jan 30, 2008

I have on sheet1 of my workbook a number of rows of data, from column A through Column G. The Data in column G either contains the text "Yes", or "No".

I need a macro that will look through each row in this sheet, and upon finding a "Yes" in the cell in the column G, will copy that entire row (columns A through G) into a new row in sheet2. Sheet2 currently contains data, so I'd like to move everything down by one row and paste this data at the top (row 6 is the first line of data on this sheet).

I'd then like to go back to sheet 1, and delete the row I've just copied. Then continue though the loop. The loop needs to stop when a blank row is discovered.

View 5 Replies View Related

Remove Subject Data Based On Criteria

Mar 17, 2014

editing a datafile. I have a spreadsheet (Sheet2) that looks like this (Start Date is entered in J2 in Sheet 1 and End Date in J3 in Sheet1):

Date & TimePatient IDResultLevel
13/02/2014 14:1818.5>=4 AND <=15
13/02/2014 14:1027.8>=4 AND <=15
13/02/2014 02:231122.5>20
13/02/2014 06:191116>15 AND <=20
13/02/2014 10:081110.2>=4 AND <=15
13/02/2014 14:111113.4>=4 AND <=15
13/02/2014 17:541112.9>=4 AND <=15

[code]....

I need to find the maximum and minimum value for each subject. If the min>4 and max<10 and the subject does not have a value on either the last date (J3 in Sheet 1) or the date before that (J2 in Sheet 1 - 1), I need all of their data removed from the spreadsheet.

View 1 Replies View Related

Moving Rows Based On Criteria (loop)

Jan 30, 2013

I was wondering if i can cut & paste rows to a different worksheet ("sheet2") based on a criteria my current loop is as follow need filling in the code below for if then ..

Sub moving()
Dim x As Integer
x = 0
Do While x < 12
x = x + 1
Cells(x, 4) = ""
Do While Cells(x, 4) = "absent"
If Cells(x, 4) = "absent" Then .....

View 9 Replies View Related

Loop Criteria Based On Unique Values In A Column

Apr 3, 2009

i had a database from which i need to extract data from COlUMN B, select the

View 2 Replies View Related

Start/Stop Loop Based On Condition/Criteria

Aug 31, 2006

I have a piece of code that put a check in all checkbox in column B from row 5 to row 50 but in column C, I have data from row 5 to 38. I want the macro to stop at row 38 in column B. When the cell in column C is empty stop putting checks in column B. How can I make this macro Check all checkbox down column B and stop when column C is empty. How do I add a loop to stop when the cell in column C is empty?

Private Sub CommandButton1_Click()
Dim CB As Variant
For Each CB In ActiveSheet.CheckBoxes
CB.Value = False
Next
End Sub.......

View 3 Replies View Related

To Merge Variable Number Of Cells Into One Single Cell Based On Criteria

Sep 19, 2009

Here’s an example of my data:

A B
1110AAAAAAA
2220BBBBBBBB
3330CCCCCCCC
4330DDDDDDD
5330EEEEEEEEE
6440FFFFFFFFF
7440GGGGGGG
8550HHHHHHH

I need your help to figure out how to merge the above data to look like this in new blank worksheet using a VBA macro:

A B
1110AAAAAAA
2220BBBBBBBB
3330CCCCCCCC
DDDDDDD
EEEEEEEE
4440FFFFFFFFF
GGGGGGG
5550HHHHHHH

View 10 Replies View Related

VBA - Advanced Filter / Find Row Items To Remove Based On Multiple Criteria

Jun 28, 2014

I'm working with many rows of data (500,000+) and many columns. To simplify my question, I'm going to provide a simple example using made up numbers and only the columns I'm concerned with.

BillT Doc.ItemQty
F11231012.00
F2123205.00
S1123105.00
RE321202.00
F2321108.00
F2321201.00
RE321203.00
RE999808.00
F27771001.00
RE7771001.00

I am trying to remove the docs that have two Bill types that cancel each other out, where the qtys match and highlight the rows where the qtys don't match. The macro needs to have the positive and negative bill types programatically entered, where for example F1 and F2 are positive and S1 and RE are negative. Keep in mind the data may not necessarily be in order as it is above.

So for example with data above, the rows for doc 777 would be removed completely because the item numbers are the same, the qty is the same, and the bill types oppose each other. Doc 123 and Item 10 lines should be highlighted since their bill types are opposed bu their qtys don't match.

I hope this makes sense. I tired to achieve this using multiple loops and arrays, but ran out of memory when working with the entire set of data. I'm assuming their must be a better way to do this, I'm hoping some of the intelligent individuals here will be able to point in the right direction.

View 8 Replies View Related

Copy Column Data From Multiple Worksheets To Single Worksheet Based On Header Criteria

Oct 18, 2013

I have a workbook with many sheets of similar but not identical data. I need to extract columns from each sheet based on 5 header criteria and paste them to a single sheet. Each worksheet contains these 5 criteria.

I've been working with the VBA script I've pasted below. It's grabbing the 5 column criteria that I have in sheet 12, and comparing them to sheet 1 in the workbook, then copying them to sheet 12. This much is good, but I need the script to also return the data from the other worksheets as well. I've tried modifying the script based on other loop functions in other scripts I've found, but I'm not having any luck.

View 14 Replies View Related

Select Row Based On Cell Criteria Remove All Formulas From Row And Change Fill Color

Apr 23, 2014

I have a worksheet that when a row changes based on the value of column B, I want to remove all of the formulas found in the row but keep the existing values, and then change the color of the row.

In the sample file attached, when the value is "Closed", that row will keep the existing values and then it gets grayed out. Rows that are still marked "Open" need to retain the formulas in case other information changes.

I have tried copy/paste special using autofiltering but that doesn't work because of the hidden lines. This file changes on a daily basis and I need a quick way to update the file.

SampleFile.xlsx

View 1 Replies View Related

Loop Through Sheets And Convert Specific Formula Cells To Values Based On Criteria?

Jan 9, 2011

I looking for a macro that will go through multiple sheets & change specific cells to values if the column header is = to value set in specific cell.

for example

I would like the macro to look at row 3 in each tab (page 1, page 2, page 3) and if the value you is equal to X (parameter input on different sheet) then change the formula to a value in row 6 & row 12 of that column.

I'm attaching an simple example that i looking for this on. The green cells are the one i would like to change to a value.

Book1.xlsx

View 8 Replies View Related

Reverse VLookup (Index Match) To Return Multiple Values Based On Single Lookup Criteria

Jul 11, 2012

I have encountered a situation where I need to essentially accomplish a reverse Vlookup (using index match) and return multiple values.

View 1 Replies View Related

Delete Row Based On Criteria

Mar 14, 2014

Formula below works for one string, "review" but i also need it to work for "audit" "project" and "done" too.... so essentially someone can go into the sheet - hit a button and remove all these lines in one go.

[Code] ......

View 7 Replies View Related

Delete Row Based On Criteria

Dec 10, 2012

I would like to obtain the below issue using VBA. I would like to delete the row if the criteria hasn't met. For example,

If cell "B3 = Dec-12" and if cell C3 is not equal to "31" then delete the entire row.
If cell "B4 = Feb-12" and if cell C4 is not equal to 29 then delete the entire row.
If cell "B5 = Feb-13" and if cell C5 is not equal to 28 then delete the entire row.

This need to be applied for the last row in column A.

Basically I am looking if column B has month and Year (i.e. MMM-YY) and if column C doesn't have that particular month days then the entire row has to be deleted.

View 3 Replies View Related

Delete Rows Based On Two Criteria Within Each Row

Sep 24, 2009

I have a sheet with say 1000+ rows that is a QA report of possible mistakes found in a employee rostering tool.

The report finds all occurrences where the staff member only has one coffee break rather than the two they are entitled to. However, on days where they have training, or other half day commitments, on of the coffee breaks is not entered into out tool. This means we are getting a whole lot of entries that we do not require(i.e. one coffee break error).

The tool uses icons but the cells do have a single unique character under each icon type. For example, the coffee break cells have a "T" and training cells have a "&" underneath the icon (without quotes). The staff members day is separated into 15 minute blocks and each block occupies a cell in a column. This means each staff members day spans many columns in a row (i.e. C=8am, D=8:15am, E=8:30am etc...).

What I have been trying to accomplish is to create a macro in VB code that will locate any row with both a "T and a "&" and delete it. This will eliminate occurrences that we are aware of and leave only genuine errors. There are other combination's that I would like to include also such as:
"T" "["
"T" "#"
"T" "@"
"T" "]"

The first row is headers and the first two columns contain team names and staff names which I am trying to exclude (because names contains "T"'s ).

I have spent many hours now looking for example code on Google, this forum and other forums, however most of the examples I have found are looking for two criteria within a column or specific criteria that is not suitable to my application (i.e. values <> certain numbers etc...).

View 8 Replies View Related

Delete Multiple Row Based On Criteria

Dec 15, 2009

if in column A in some row is text "today" then delete this row and delete all rows until in row B wont be empty cell. I have start (If in A is "Today" then ... ) but thas's all

View 5 Replies View Related

Delete Rows Based On Criteria?

Jan 23, 2010

I had a raw data sheet in which i need to prepare a statement just like the attached worksheet.

My requirement is to delete all those rows in the department column except the department which starts with "C" Just like "CNN" & "CNN-IN".

Rows with data containing the words starting with "CNN" should not be deleted .The rows can contain words with "CNN" or "CNN*"(here * denotes anything after the word CNN)

I had just formatted the whole worksheet for easy reference.Actually the raw data is extracted from other program which is very clumsy & irregular.

The department column might be in any column.

View 14 Replies View Related

Delete Row Based Upon Multiple Criteria

Dec 7, 2006

I am attempting to create a macro that will delete an entire row, based upon multiple criteria. The data looks something like this:

-----Column A-----------Column B---
1.-- Computer_X ------- Software_A
2.-- Computer_X ------- Software_B
3.-- Computer_X ------- None
4.-- Computer_Y ------- None
5.-- Computer_Z ------- Software_A
6.-- Computer_Z ------- None

I would like to delete the entire row if:

1) Column B entry is "None"

AND

2) Column B has entries other than "None" that match Column A

So I do not want to delete a row with a unique name in Column A and "None" in Column B. I only want to delete the rows that have "None" in Column B, and multiple entries for the match in Column A.

Using the data example above, Row 3 and 6 would be deleted. Row 4 would not be deleted, since Column A (Computer_Y) had only one row of data, with "None" entered in Column B.

View 9 Replies View Related

Delete Based On Condition/criteria Using VBA

Apr 16, 2006

I want to be able to delete certain rows based on multiple criteria. If data in the row does not meat the crieteira, it shud be deleted. I have attached the excel file sample in which I want to keep the highlighed rows and detele the rest. Its base on Origin city and Destination city combination. Eg: If Origin city="A" and Destination City = "B", I want to keep the row. Like wise for all highlighted rows. but if the Origin City = "B" and Destination City = "U" I want to delete the row.

View 9 Replies View Related

Delete Rows Based On 2 Criteria

Nov 30, 2006

Is there a vba code that can delete the entire row based on two criterias? If a row has a location of Canada and is a female, then delete the entire row.

Name Location Gender
Alan Mexico Male
Dick USA Male
Sharon Canada Female <-- This will be deleted if based on criteria
Mike Canada Male

View 3 Replies View Related

Delete Rows Based On Criteria ..

Jul 19, 2007

I am a pharmacist that runs reports and I need to sort and exclude data

It is in Excel 2003 format

I run a report that includes a patients name in one column, the medications name in another column and if the medication was withdrawn, wasted, returned or restocked in another column. Withdrawn, wasted, returned or restocked are treated as different functions and each have their own row entry. Patient and medication name are the same in all situations

I need a macro that will look at the patients name and medication name, see if it is the same and delete all rows that have a withdrawal with an associated wasted, returned or restocked.

View 9 Replies View Related







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