Delete Rows If Column Has Fewer Than X Matches To Part String Match
May 5, 2008
I have data sets on multiple worksheets within a workbook (over 70). Based on the begining of a string, I need to count all instances with that begining, and if there are fewer than 12 instances, delete the entire row.
Data set example:
In this example, I need to count each instance of rows starting with 1/* - 9/*, and delete rows as mentioned. In other data sets the string might start Gi1/*, and so on. In the following code, if I do not loop, and only test against 1 value type, and ONLY run it once, it works. As soone as I try to loop through all possibilities, or run the macro a second time, it blanks out the entire worksheet, starting at row 3.
Dim c As Long
c = Worksheets(i).Range("A" & Rows.Count).End(xlUp).Row
With Range("A3:A" & c)
If Application.WorksheetFunction.CountIf(Worksheets(i).Columns(1), "1/*") < 12 Then
. AutoFilter field:=1, Criteria1:="1/*"
.Offset(1).Resize(.Rows.Count - 1, 1).EntireRow.Delete
.AutoFilter
I have also tried to concatenate a variable with my CountIf criteria, but that fails miserably.
I have a spreadsheet that is updated daily with data that falls into one of two categories: a) completely new to the sheet or b) existing from the day before but not taken care of yet. The items which fall into category a are evaluated, and notes added to the sheet. The items in category b must be compared to the new data, and duplicated lines deleted but notes from previous evaluation must be kept on the sheet. In addition, anything on the sheet that is not included in the new information needs to be deleted. I've set up a sheet with all old and new data with dates the data showed up as well as the notes associated with the old data, and have concatenated all the info from each row into column V (from another suggestion I got on a similar but not exactly the same problem which I also still haven't figured out). The sheet has been sorted by col V so any matching rows should be within 3 or 4 rows of the original. The problem is that my code does absolutely zilch!
Sub DeleteRepeatedRows() ' goes through coord. sheet and identifies duplicated lines, copies the date from the old row ' copies it into the new line, then deletes the old line Dim rCell As Range For Each rCell In Selection If rCell.Value = rCell.Offset(1, 0).Value Then rCell.EntireRow.Delete End If If rCell.Value = rCell.Offset(2, 0).Value Then rCell.EntireRow.Delete End If.........................................
I have an excel file, and on some rows, the "B" column contains the text " Total:" (it does have a leading space). I would like to loop through the first 200 rows (maximum length of the file) and delete all the rows that contain " Total:" in column "B". I have tried:
For i = 1 To 200 range("B" & i).activate If range("B" & i).value = " Total:" Then rows(activecell.row).select selection.delete shift:=xlUp End If Next i
When I step through that code, it just skips over the IF function as if B1 does not equal " Witness:"
I have a worksheet that I need to filter on 8 columns. I need to do this in the form (Col A = Bob OR SAM) AND (Col B = Apple OR Pear OR Banana) AND... etc for 8 columns.
I started this thread and we reached the conclusion that I needed either a macro to list out all the possible combinations on separate lines, or a complex criteria formula.
I'm trying to put together the complex criteria, but I am further stumped by the fact that some of the columns contain multiple terms with comma delimiters, so I'm trying to match part of a string, rather than a whole string, so the usual = ISNUMBER(MATCH(Sheet1!A2,Sheet2!$A:$A,0)) won't work. I tried using =ISNUMBER(FIND(Sheet2!$A:$A,Sheet1!A2)) instead, but I think this fails because it should be an array formula. I tried normal entering and CSE entering, and neither work, so I think this is a dead end.
I m trying to evaluate part of a string to determine if a number and if 6 char's in length. If Yes, return the 6 digit number, else 0
My formula below returns a #VALUE! error It worked before I added the 6 char length condition, but sometimes return values of greater length that I do not need.
I am trying to delete part of a text string for a range of cells. The code I have so far deletes the first set of letters but is looking in every cell in the range.
Ideally I would like it to only look in the cells of col B where there is data then only delete the first 10 letters if the cell begins with "Service ID"
Sub DeleteServiceID() Dim c As Range For Each c In Range("B1:B1000") c.Value = Right(c.Value, 10) Next c End Sub
I am looking for a formula to delete information from the middle of a text string. I have ~ 1,000 lines of data. Each text string is composed of the same way. The data I am looking for is two parts of the string (1) all the text up to and including the first “%” character (2) the last six characters.
Raw Data CARDINAL HEALTH 5.5%13CARDINAL 5.513 CARDINAL HLTH 5.5 061513 UST BILL 0%09US TREAS BILL 0%09 UST BILL 0.0 092409 WORLD SAVINGS 4.125%09WORLD 4.125%09 WORLD SVGS 4.125 121509 JP MORGAN 5.375%12JP 5.375%12 JPMORGAN CHS5.375 100112
Desired Result CARDINAL HEALTH 5.5% 061513 UST BILL 0% 092409 WORLD SAVINGS 4.125% 121509 JP MORGAN 5.375% 100112
I have a tab that has 2 columns of data and I want to be able to return a value in column A if my data matches column B. If column B has the text TRUETRUE, I want to bring back the corresponding data in Column A. How do I return all the data in Column A for all the TRUETRUEs in column B? I can only get the first instance of TRUETRUE.
I would like to match column data in a source spreadsheet to column data in a target sheet. If a match is found, I would like to copy the corresponding row range from the source sheet to a separate, third sheet. For values where no match in found in the a target sheet, I would color the unmatched cell in the target sheet red. If a match was found, the cells would be colored green. The data in the Source sheet is in column A, while the Data in the Target sheet is in Column T. The data will be pased in the third sheet in Column T preserving original formats
I have this code, gleaned from several postings on this forum that somewhat works. The problem is that I get false mismatches (i.e. some cells get colored red even when there is a match and the data got copied to the third sheet) even though there are no duplicates. I have made sure that the formats are identical in both Target and Source sheets to try to fix this. Also, I don't want to cut the entire row , but just copy and paste a row range onto a third sheet. The column and row ranges are variable. I am attaching a file.!!
Sub CutRows() Dim i As Long, k As Long, n As Variant, r As Range Application. ScreenUpdating = False With Sheets("Source") Set r = Range(.Cells(1, 9), .Cells(65536, 6).End(xlUp)) End With k = 0 i = 6 While Not IsEmpty(Sheets("Target").Cells(i, 20)) n = Application.Match(Sheets("Target").Cells(i, 20).Value, r, 0) If IsNumeric(n) Then Sheets("Target").Cells(i, 20).Interior.ColorIndex = 35 k = k + 1 Sheets("Source").Rows(n).Cut Sheets("Sheet3").Rows(k) Else Sheets("Target").Cells(i, 20).Interior.ColorIndex = 3 End If i = i + 1 Wend Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
I have a spreadsheet of several thousand named items (in column B) with values associated with them in column A). The "name" field is a string of several alternative names for the item.
I have a list of ~50 items that I am trying to find the values for. Each uses one of the alternate names.
What I want is a function that will return the associated value in column A when one of my shortlist names is found.
In column B & C, starting at row 2, there are first names & surnames. In column H there is a grade for each name, eg B. Columns AC through AH hold subject codes for each name, eg 18E/Hs1 (potentially all columns could contain a code or only 1). The identifying part of the subject code is the first 2 letters after the / . So in the example the subject code 18E/Hs1 the 'Hs' signifies it is History. A table of subject code and their subject name is contained in a named range called Subject_ID (see below). I intend to make this range dynamic.
For each name (starting at row 2) I want to achieve the following: Scan across the range containing the subject codes (AC:AH), identify the first two letters after the / and match it to the subject name in the list. Paste the subject name to a cell starting at AI1 and then insert the grade (contained in column H) for that student in the corresponding subject column. The next unique subject name should then miss a column be pasted in AK1.
should result in the word History in AI1 and English in AK1 and the letter D in AI2 & AK2. Note as there is already a reference to History this is not repeated again.
I hope this is clear. I have enclosed a sample workbook with expected output and colour coded the subject names so that the order that they are pasted in is evident.
I have two columns with dates. Colum A has the date of the deadline of a document while column b has the day it was sent. Column X will display the difference if its a positive integer ( i.e. if the document has been sent after the deadline). Now i have another column Y which displays the month as an integer of when the document was actually received.
Now i need a counter which will count the number of instances a positive integer is registered in column X according to the month in column Y. I have been trying everything but cant figure a simple way to do it. Im doing this so i can be able to see how many documents are sent after the deadline per month.
I have a column of data with letters in each cell, no numerical, only alpha. Now, some of those cells contain the letters "adj sub" as part of the text string in each cell. "Adj sub" is always at the beginning of the text string. As an example, a cell will look like this - "adj sub mhm". I want to delete rows whose cell description does not contain "adj sub" as part of the text in the cell.
I am trying to move through the worksheets and delete all columns with "Accession" in contained in them. I have to do this with an external macro as the spreadsheet with the data is created from another program. I tried this and get an 'Object or With block variable not set' error and the debug highlights the Cells. Find line of the code.
Also, the number of columns could be variable within the spreadsheet as it is compiled by the other program.
Sub DelAccessionNum() Dim Wrkst As Worksheet For Each Wrkst In ActiveWorkbook.Worksheets Cells.Find(What:="Accession", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False _ , SearchFormat:=False).Activate On Error Goto Completed: Selection.EntireColumn.Delete Shift:=xlToLeft Completed: Next End Sub
Is there any way to remove the first part of a string of text in a cell and save the second part?
The first part of the text string is a team code that has a variable number of numbers, capital letters and sometimes spaces. The second part of the text string is a variable number of words in a team name that all start with a capital letter and have lower case letters. Every line has a different team code and team name.
The original spreadsheet also has a column with just team code. Is there a way of using this column to "subtract" the team code from the text string to just leave the team name?
I was given this new task this year. Normally this process is done by hand, by one of the managers, but since it now belongs to me, I look at it as being a little to tedious to do. So I would rather have excel do it for me.
We have about 5 CSRs who handle clients based on the first letter in the clients name. I guess to make this easier to update in the future if the macro would respond to a cell reference for the number of CSRs that would be great. I will need to perform this task Annually, and of course each time a CSR leaves or we hire another one. This way work loads are kept close to the same.
I have a list of letters in column A. Each of these letters has a corresponding number of clients in column B. I have been given the task to try to split these values equally between the 5 individuals. I know that since the numbers don’t all add up and divide equally it can’t be done easily by hand.
I have attached an excel file with what I have in the sheet. Sheet 2 shows what I would like to have as an example as output on the same sheet. (What I put on the sheet is an example of the way I want it to look, are not close to adding up to a "close to equal" total.)
There are probably simple solutions to these problems but I'm fairly new to Excel and i have spent far to much time trying to figure this out.
I need a macro that will delete rows that do not contain the string "QC"
Only column A is populated and "QC" is always at the start of the string followed by a space then more characters.
I would also like to delete the contents of the remaining cells (cells that do contain "QC") with the exception of the 5 characters (inc space) immediately after "QC"
column "b" in the attached file has numbers that match some numbers in column "c" I need to delete all the rows that done match the numbers in column "c" that are used in column "b"
for example no " 53" is in column "c" but not column "b" so they need deleting
I'm trying to put together a script which on the sheet "Resource" compares every cell in the range B:U, starting at row 8, and where all cells match, keep the first row, but delete the duplicate proceeding rows.
I've found the code below here: [URL] ...., which I thought I may be able to adapt, but for me to include all the columns in the 'If.Evaluate' section of code seems to perhaps not the most efficient way of doing this.
I have a file which has some data I want to keep and some data I want to strip out.
The data I want to keep will always have either a date or a string “Overdue” or a string “> 1 year” in the first column, anything else I want to remove.
I'm trying to create a macro that will delete all rows with "CAT" in the REF column. I've searched this site and struggled trying to adapt other methods listed and got nowhere.