Deleting An Entire Column
May 2, 2006Need the code for deleting multiple columns simultaneously in an excel depending on some search criteria.Suppose I want to delete the columns whose names are "Roll No" ,"Age" & "Class"
View 2 RepliesNeed the code for deleting multiple columns simultaneously in an excel depending on some search criteria.Suppose I want to delete the columns whose names are "Roll No" ,"Age" & "Class"
View 2 RepliesWorking on some code that will find the Column Name "CL" and delete the entire column. Here is what I have so far...it does not give me a error when it compiles, but for some reason the statement in red is being ignored. I tried switching Range with Columns, but that did not work.
Private sub coldelete ()
Dim Rng2 as Range
shUCLR = sheets("Unit Cost").usedrange.rows.count
Set Rng2 = Sheets("Unit Cost").Range("A1:BF1")
For Each d In Rng2
If d = "CL" Then
colnum = d.Column
colletter = Left(Sheets("Unit Cost").Cells(1, colnum).Address(False, False), (colnum)
I have a spreadsheet with thounsands of rows. Some of the rows I'd like to delete because thier values are below 5%. I wrote a VBA code, which primary function is to look for a cell and delete the row if the value is less than or equal to 5%. The code looks fine but I get an "Infinite Loop" anytime the first row value is not true. Below is the code,
-jungleman1
Sub Delete_Zero_Factors()
Dim i As Integer
Dim CUSIP As String
Sheets("Report").Select
Range("B5").Select
i = 0
While Not (IsEmpty(ActiveCell.Offset(i, 0).Value))
CUSIP = ActiveCell.Offset(i, 0).Value
Do While (ActiveCell.Offset(i, 1).Value
I am trying to delete entire row that has certain text, let say "hi". I was able to delete cells with exact word "hi", but was not able to delete cells that have texts other than "hi". ex) "hi myname." Below is my vba code, and I keep getting run-time error and cannot execute the code.
VB:
Sub HiDelete()
Dim srchRng As Range
Set srchRng = ActiveSheet.Range("g:g")
For i = srchRng.Rows.Count To 1 Step -1
If worksheefunction.Search("hi", Cells(i, 7)) > 0 Then Rows(i).Delete
Next i
End Sub
I've been tasked with developing a macro that will generate schedules. For background, we're taking a QuickBooks Customer file and exporting it to be picked up by the macro. I've got that part working, but now I need to delete various rows based on certain criteria.
The spreadsheet has a field for Job Status which we use to define whether an account is under contract (2 in QuickBooks), or some other status. Basically what I need to do is delete the entire row of data where JobStatus (Column R) is anything but 2.
I currently have the following code that works great and deletes the row from my spreadsheet when the word "vacant" appears in column F.
Sub test()
Dim r As Range
With ActiveSheet[code]....
The problem is, "Vacant" also sometimes appears in column G. So, as this code is now it is finding the word "Vacant" in either column F or column G and then deleting the row.
How can I write the code so that it only deletes the row where "Vacant" appears in column F but ignores it when it is in column G?
Sub Delete()
Dim x As Long
For x = 28 To 8 Step -1
If Range("b" & x) = "" Then _
Range("b" & x).EntireRow.Delete
Next x
End Sub
I've got a report which is approx 40,000 rows long and I need to delete out alot of the info.
I need to delete out entire rows if column C contains a 0.
I've written a loop to do this but as theres so much data it take a long time to run.
Is there a smarter way to do this?
I have a long list (over 1000 lines) of numbers, some of which are duplicated. Up to now I have been sorting them, adding in a simple check column to see if the number is a duplicate of the one below, and then manually deleting this cell.
Is there a better way to do this using VBA? The only way I have managed to find is by deleting the entire row, but I cannot do this as I have additional data to the right that I need to keep.
I also cannot install any add-ons as this on a work computer.
I have a large database of customers. I would like to edit this database so that it only lists those customers that have an email address listed in that particular column. I can then save that as a separate list to upload to my marketing campaign.
Is there an easier way than just deleting entire rows at a time? About a 2,000 name list with maybe 30% having email addresses.
I'm trying to come up with a macro that can delete an entire column based on formatting of the cells. Basically what I have is a range of cells, and if all cells in a particular column have no fill color, then delete the entire column.
View 9 Replies View RelatedI have an excel work book with 6 tabs. I would like to have Excel move an entire row from one tab to another tab (removing the row and inserting it in the other tab). I.e. Example I have a tab with items that are marked as "Open Actions" so if I were to change the drop down to close. Excel would move that entire row of actions to the tab with the "closed actions" and insert into the next available row. Now if someone were to come back at a later date say no it should be reopened than I would change the drop down to open and excel would move that row back to the open actions tab into next available row. I tried a PIVOT table and no good I played with few macro and not.
View 5 Replies View RelatedI am running Win XP and Excel 2003.
I have a macro I found here on the boards written by Lenze to delete an entire row based on what is found in column A. I would like to delete any row where Col. B contains 10 or less characters and I have modified it to do so (or at least I think it does). My problem is that it takes about 12 minutes to run the macro (I have about 50k lines to run through). I was wondering if this is the fastest method or if it examines things other than just column B.
Sub Test()
Dim i As Long
LR = Cells(Rows.Count, "B").End(xlUp).Row
For i = LR To 2 Step -1
If Len(Cells(i, "B")) < 11 Then Cells(i, "B").EntireRow.Delete
Next i
End Sub
After this runs, I am left with Columns A to somewhere around AH. The columns are generally in the format of text followed by a numeric column. An individual text column has the same name through all of the rows. The numeric columns have varied values whether negative or positive.
Ideally what I would like: If a given cell (ie. C2) in Row 2 is numeric, then copy the cell to the left (ie. B2) into (ie. C1) and then delete Column B. I need this to work for multiple columns from B to C, skip D and E, and then from F to AG (and maybe beyond).
Does anyone have a macro that will delete entire row if column a matches column d
View 6 Replies View RelatedI need to do the following:
I have a list of cities on one sheet. The headers are the counties and below each (6 columns) are all the cities names.
I need to be able to show all the cities of a specific column on a nother sheet (autofilling column down with all cities names) when i type the name of the related county in an adjacent cell.
The subject summarizes what I want to achieve. I just want to tie an if statement to an entire column, so it will disappear if a statement is satisfied.
View 4 Replies View RelatedI'm inserting new information at the top of my worksheet. Unfortunately the formula for what WAS row one: =SUMIF(TotalSales!$B:$B,A1,TotalSales!$H:$H) Will no longer work for row one because as more date is collected row 1 shifts down to row 2. Row two still looks good but there is no longer a formula for the new rows inserted.
To be clearer... I would like to have the following:
=SUMIF(TotalSales!$B:$B,A1,TotalSales!$H:$H) in cell B1
=SUMIF(TotalSales!$B:$B,A2,TotalSales!$H:$H) in cell B2
=SUMIF(TotalSales!$B:$B,A3,TotalSales!$H:$H) in cell B3
How can I keep that formula in row one as I keep inserting new rows?
I have created one excel which contains column with range. (A1:A6). and the drop box included the values as Passed, failed, NA, NC) i have coded the the macro to change color as if i select passed from A1 then A1: F1 will be Red. please find the below code.
Sub Prasanna1()
Range("A1").Select
Select Case Range("A1").Value
Case "Prasanna"
Range("A1:F1").Interior.ColorIndex = 7
Case "Kale"
Range("A1:F1").Interior.ColorIndex = 0
[Code]...
The code is working fine for one row. Now i want to set the same code for entire column A. as if i will select A10 the same range of row should get change with fill color.
I have a work book with a lot of information. In column “W” I have a text comments, cells in this column probably have something or not, and the text is very variable. What I need is an instruction to look at entire column for two key words for example: "na co", "apna" or "apcredit" ... in case of one of these words its found I need the macro to make a process.
For example if in the column W there is any item (cells) with text "apnapo" then
First filter the information:
Selection.AutoFilter Field:=23, Criteria1:="=*apna*", Operator:=xlAnd
Range("K1").Select
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.EntireRow.Hidden = False
ActiveCell.Offset(1, 0).Select
Loop
Then write down something in columns K & L
ActiveCell.FormulaR1C1 = "Ion Apnapo"
ActiveCell.Offset(0, 1).FormulaR1C1 = "Pamela Elizondo"
Selection.Offset(0, -1).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Offset(0, 1).Select
Selection.FillDown..................................
As the title sugests I would like to Select a cell and a macro will highlight the row and column
Sub Select_Entire_Row()
Dim RowNo As Integer
Dim ColNo As Integer
RowNo = Selection.Row
ColNo = Selection.Column
If RowNo.Value >= 1 Then
Cells(RowNo, ColNo).EntireRow.Select ' I want it to do both not one then the other
Cells(RowNo, ColNo).EntireColumn.Select
End If
End Sub
I have two worksheet. One worksheet (ws1) contains a list of item I want. The other sheet (ws2) contains multiple columns where the header (row 6) is named by item name.
I have the following code which deletes the entire column if the header name is not in the list contained in ws1 :
VB:
Sub delete_col()
Dim wanted As Boolean
Set ws1 = Workbooks("test1").Sheets("aaa")
[Code]....
First of all, this loop does not work properly since deleting the entire column shift them on the left, so when I first analyze column 11, if I delete it and then analyze column 12, the real column 12 now became column 11 and so on...
Secondly, this code is pretty slow. I am pretty sure I don't have to loop through my initial item list everytime I do Instr on a new column.
i know how to make a drop down list and then I can strech it over X rows but how do I set somthing like from C3 and forever onwards (C4,C5,C6..)use this droplist. I do not know how many entrys will be made so from C3 and onwards I need all cells to have this drop down menu.
View 2 Replies View RelatedI have a list of number in a column that there is over 22,000 is there a away I can add ".jpg" ad the end of each number?
View 10 Replies View RelatedI want A1:A400 to display in B1.
View 6 Replies View RelatedI have columns
Row 1 is heading..
IF Column C doesn't have data in entire column then delete C D E F
IF Column D doesn't have data in entire column then delete D E F
IF Column E doesn't have data in entire column then delete E F
IF Column F doesn't have data in entire column then delete F
Same way for heading NN's
IF Column G doesn't have data in entire column then delete G H I J K L M N
IF Column H doesn't have data in entire column then delete H I J K L M N
IF Column I doesn't have data in entire column then delete I J K L M N
IF Column J doesn't have data in entire column then delete J K L M N
IF Column K doesn't have data in entire column then delete K L M N
IF Column L doesn't have data in entire column then delete L M N
IF Column M doesn't have data in entire column then delete M N
IF Column N doesn't have data in entire column then delete N
i want to delete entire row if D2:D10000 has a numeric value e.g .111 to 100000.1114
View 4 Replies View Relatedi want to delete entire row if Column C2:C1000 are blank
e.g if range c2:c100 have data then delete the rows C101:C1000
I have fixed headers on row 16, from columns A-AC.
I want to be able to delete the entire column, if the row has a certain string, such as "Chart ID" .
I also want to expand it to include other strings such as "Month" and "Source" . So if it contains any of these words, the columns should be deleted. It should be an exact match (as other headers contain the word "month").
I recored a macro to Cut the entire "E" column and paste on "A". For some reason when i read the code it doesnt capture the part where it needs to paste it in column "A".
View 1 Replies View RelatedIm trying to compare sheet 1 Column A, with sheet 2 Column A, and then move any duplicates (along with the row of data) from sheet 2 over to sheet 3.
For instance, Employee Numbers that match in both sheet 1 and 2, remove that entire row from sheet 2 to and insert it into sheet 3.
VBA that compares sheets and moves duplicates found in column A to sheet 3 but it leaves the rest of the row on sheet 2.
[Code] ......