Deleting Range Of Cells Using VBA
Jun 12, 2009
I need to have my macro select a certain range of cells with a specific product code and delete them. What would be the code for it (product code 107). Here is what i have so far:
Workbooks.Open Filename:=fNameAndPath, UpdateLinks:=1
ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:=myStrPath1 & myStrPath2 & myFile3 & myExt, FileFormat:=xlNormal, CreateBackup:=False
Windows(myFile3).Activate
Cells.Select.Range ("A78:K153")
Selection.Delete
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A1").Select
ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:=myStrPath1 & myStrPath4 & myFile4 & myExt2, FileFormat:=xlCSV, CreateBackup:=False
View 9 Replies
ADVERTISEMENT
Jun 11, 2014
I have a sheet with thousands of rows and 45 columns and I need to delete a range of cells (G:Y) if the cell in column V = the cell in column X, and I need to do this by row. I think an if/then statement would work.
View 4 Replies
View Related
Jan 29, 2014
I want to create a macro that will find a text string called "Season Average" in the entire workbook and delete a range of cells above it 4 cells longs starting right above the text and then going left.
Example is if "Season Average" is in cell D11, than I want the cells D10, C10, B10 & A10 Deleted and the cells to shift up
This happens throughout the entire workbook and multiple times on each work sheet in different spots not consistently same cells.
View 9 Replies
View Related
Jun 2, 2014
I have a target range for a worksheet change. Then when finished I highlight the data and press 'delete' I get an error within the code.
View 2 Replies
View Related
Aug 1, 2013
I am attempting to make a range of cells' data be deleted if a cell outside of that range that had a name in it is no longer there. So if I have a list of names in cells A1:A6 and a range of data in cells D10:E20 that corresponds to a name in cell A2. If the name in A2 is deleted I would want the data in D10:E20 to be deleted.
View 9 Replies
View Related
Feb 17, 2010
Say i have a range A1:B3 and i define it as "Fruit", but then later decide i want to call it "food", or even just revert back to cell numbers. How would one go about doing this?
View 5 Replies
View Related
Aug 24, 2007
I'm trying to remove gif, jpg, and xls objects from a specific range and I can't seem to figure out how to do it. I can remove all objects from the sheet or only the gif and jpg files from a range. Here is the code I've been playing with:
Sub Clear_Sigs()
Dim Sh As Shape
With Worksheets("Sheet1")
For Each Sh In .Shapes
If Not Application.Intersect(Sh.TopLeftCell, .Range("A26:E32")) Is Nothing Then
If Sh.Type = msoPicture Then Sh.Delete
End If
Next Sh
End With
End Sub
I know this code says to delete only pictures and I've tried tweeking it to do all objects but it doesn't work for just the range I want. Any help is appreciated.
Thanks,
Amy
View 9 Replies
View Related
Mar 22, 2013
I have the following problem within Excel. I have a dataset which contains duplicate values within a column(lets say A). I need to delete these duplicates in column A for a range of rows, where the range of the rows is based on column B. So for a given value in column B, lets say 5 which is 6 rows long all beneath each other, I need to delete the duplicates in column A.
A B
1 2234
4 2234
5 2234
4 2234
2 2234
3 2234
5 2234
5 2657
8 2657
9 2657
10 2657
8 2657
9 2657
2 2657
So above the red numbers need to be removed, automatically, since we have about 8000 rows in our dataset.
View 7 Replies
View Related
Oct 2, 2011
How can i delete a range of cell in another worksheet 2? for example, i have a data in B1:F1 in sheet 2 and i want to put a button in sheet 1 which will delete the data in B1:F1 in sheet 2.
View 1 Replies
View Related
Oct 2, 2012
Any easy way of finding out if deleting a particular sheet / range or selection will mess up any references elsewhere in the workbook?
View 1 Replies
View Related
Nov 13, 2013
I'm pretty new to coding from scratch in VB, and I've got some code that should loop, but it doesn't. The idea eventually will be to download a spreadsheet, make a new sheet for every item in a range, and then filter for each of those items and put it in the right sheet. I have to code to create the sheets (lightly modified from something I got here)
Sub CreateSheets()
'Written by Barrie Davidson
For Each c In Sheets("FilterList").Range("b2:b74")
Sheets.Add
ActiveSheet.Name = Right(c.Value, 30)
Next c
End Sub
That's working well, so I've tried to modify it so that it will also delete sheets based on the same range. I've gotten it to delete the first item in the range, but then it stops.
For Each c In Sheets("FilterList").Range("b2:b74")
Application.DisplayAlerts = False
Worksheets(c.Value).Delete
ActiveSheet.Name = Right(c.Value, 30)
Next c
End Sub
By the way, I don't know what the ActiveSheet.Name = Right(c.Value, 30) line does, but I put it in since it was in the code I was modifying.
View 9 Replies
View Related
Aug 15, 2007
The loop cycles through my sheet correctly but wont delete any cells.
View 10 Replies
View Related
Aug 15, 2008
I have a column that needs to be text format, but it needs to include only digits (0-9), no letters, no special characters. Also all cells need to have 7 digits.
I am trying to do a couple of things:
1 : Hightlight the cells that contain Strings with Non-Digits characters
2 : Highlight the cells with less than 7 characters (I have the code, it is below)
I have tried many ways to get #1 but I am stuck.
Help please.
This highlights the cells with less than 7 characters:
Sub StringLength3() ' IT WORKS!
Dim strTest As String
Dim i As Integer
Dim Cell As Range
'Select Range
Worksheets("tres").Activate
Worksheets("tres").Range("A2", Range("a65536").End(xlUp)).Name = "RangeA"
Range("RangeA").Select
For Each Rangea In Selection
i = Len(Rangea)
If i 7 Then
Rangea.Cells.Interior.ColorIndex = 7
End If
Next Rangea
End Sub
View 9 Replies
View Related
Apr 30, 2014
I have a data in which I have inserted a table with headers.
I then filter the type of data I want removed from the table using the drop down
Then goto special, visible cells only, press delete.
Now, the data is gone, but when I select all again to pull up the entire table, the data is gone, but rows are still there. So now I have tons of empty rows in between the rows of needed data. Any way of removing the rows in between as well as the data?
View 4 Replies
View Related
Jul 7, 2014
I need to store some numbers, all of which are prefixed by four or five zeros. When I format the cells as number, the zeros are erased. So, 0000012345 becomes 12345. The zeros are preserved when I store them as text, but I cannot do the functions that I need to do with the cells formatted as text.
How I can preserve the zeros in number format?
View 2 Replies
View Related
Feb 3, 2009
When you highlight a group of cells and give them a reference name- that name seems to be permanent. How do you delete one or add cells to the reference? Example attached book1.xls Cells A1-B3 are named "TheGroup".
View 2 Replies
View Related
Mar 29, 2009
I have a column with "1" and "0". I'd like to have something like, if the value in a cell within the column is "0", then delete the 4 cells previous to the cell that contained "0" within the row.
Instead of deleting, the values can also be replaced with anything e.g., zero or n/a etc.
View 4 Replies
View Related
Apr 14, 2009
The delete function has disappeared from my EDIT menu in excel. Delete and Insert has also disappeared when I right Click on the spreadsheet.
View 11 Replies
View Related
Dec 13, 2006
i have worksheet with peoples details in it... i have a userform with a combobox and a delete command button in it with the persons name in the combobox... and i cannot figure out how to delete the persons details with the combo box...
View 9 Replies
View Related
Sep 22, 2007
Is there a way to delete empty cells, without having to do each one individually. I have 10,000 numbers with about 500 empty cells. I did a search, but found nothing...
View 9 Replies
View Related
Sep 1, 2008
I am trying to a method to delete rows that contain EL or LE in a specific cell in a set column as this will reduce my file down by nearly a third. Currently by doing it using a autofilter it kills my computer as there is so much data. Is there an easy way to reduce this?
Trade ID456465ELColumn B456456LE Column B8454321LEColumn B456456ELColumn B5464564LColumn B4564546LEColumn B
View 9 Replies
View Related
Feb 27, 2007
I am trying to write a macro that looks at columns C-I in row 6, to check if the value is G, if it is then I want it to delete C5,6,7 & 8 and so on along to coumn I. So all that I am left with at the end of the macro are the values that weren't green without any blank gaps in the columns. I started using the following
If C6 = G Then
Range("C5:C8").Select
Selection.Delete Shift:=xlToLeft
End If
And using that same code for D6, E6 etc etc, but obviously, when it deletes the cells it shifts them left so the columns change values, so if C6 is equal to G then it deletes it but then what was D6 becomes C6.
View 2 Replies
View Related
Jun 29, 2007
I know this is an easy question....what syntax would you use if you want a macro to search Column A for every cell with specific text, and then clear that cell? I can't seem to get the syntax right to get it to do what I want.
View 2 Replies
View Related
Sep 8, 2006
I have users that submit a workbook quarterly. Many of the submissions contain name ranges that I need to remove. I wrote the below to delete the named ranges but encounter an error when the macro encounters a named range with the Kanji (Japanese) character set. How can I update this to delete these ranges as well?
Sub DeleteNamedRanges()
Dim ws As Worksheet
Dim NR As Name
On Error Goto ErrTrap
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
For Each NR In ActiveWorkbook.Names
NR.Delete
Next
Next
ErrTrap:
If Err.Number = "1004" Then
Resume Next
End If
End Sub
View 9 Replies
View Related
Mar 16, 2013
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
View 3 Replies
View Related
Jul 13, 2013
I have a VBA code which checks the value of two cells in "Sheet2", and when these values are in the fourth column of "Sheet4", then dictionary is saved and after that VBA delete Entire Rows in "Sheet4" which consists these values.
Please find the code below:
VB:
Sub dictionary1()
Application.ScreenUpdating = False
Dim dico1 As Scripting.Dictionary
Set dico1 = New Dictionary
[Code] .....
Now I wonder how to add more conditions like for example: "Delete all rows in "Sheet4" which have for instance in the 6th column text "Hello" AND which have in the 7th column value greater than 10". How can I change the existing code?
This is of course just an example, but the underlying question is how can I add to these dictionaries more conditions. Of course, we can still use "Sheet2" to add some value which we want dictionary to store.
I want to use for this only dictionaries because spreadsheet is large and filtering doesn't work at all...
View 7 Replies
View Related
May 16, 2009
I have Column A with 380 cells filled in with numbers (A1-A380) i.e. numbers like..456758, 567848 etc etc
Column B has a subset of those numbers, maybe 80-90 or so (B1-B90).
What I want to do is either highlight the numbers in Column A that also appear in Column B in yellow, OR delete them from Column A altogether
View 8 Replies
View Related
Jul 10, 2013
I just have a grid with a bunch of numbers listed and they all have one extra space at the end of the number. I have another tab with the same numbers but they do not have that extra space. I am using a vlookup formula and it is not recognizing the numbers because of the extra space. Is there some way to get rid of the extra space with a formula instead of going through job by job?
View 5 Replies
View Related
Nov 15, 2013
Can I protect cells so that people can't change them, but at the same time they are able to delete rows and columns?
If I remove the locking and use hide only then the cell why go empty if someone double cliks it.
View 8 Replies
View Related
Mar 21, 2014
I have a spreadsheet that has mostly locked cells but randomly placed unlocked cells.
The sheet is completed, often saved and printed. We then go back into it and use it for another customer calculation and need to ensure all previous entries are removed. With the locked cells you can't simply highlight an area to clear so I am wondering if there is a way to clear the unlocked cells in one step other than entering on each on to clear.
Would there be any way that if we cleared the first cell the others would clear?
View 4 Replies
View Related