Clear Range From All Worksheets

Jul 19, 2007

I have a macro to clear all contents for a sheet in a workbook. The problem is that every file has over 20 sheets of data. Is there a way I can code a for statement to clear all sheets in this one workbook? Is it possible to make a for statement for multiple workbooks with several sheets?



Range("A11:Z11").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.ClearContents
Selection.Interior.ColorIndex = xlNone
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Selection.ClearComments

View 9 Replies


ADVERTISEMENT

Clear Contents In Various Worksheets At Once?

Dec 2, 2011

I have a monthy activity where I would like to clear the area B13:P42 on various worksheets in the same spreadsheet. Is there an easier way to do this rather than just recording a macro?

View 5 Replies View Related

Clear Ranges On Different Worksheets

Dec 20, 2006

Clicking the button opens the MSgbox then on clicking Yes to run the code it stops on - Range("E3:BU98").Select - saying range selection method failed, and i cant understand why it seems to be such a simple piece of code.

Private Sub CommandButton2_Click()
Dim msg2 As Integer
msg2 = MsgBox("Has a back up copy been saved?" & vbCr & "Are you sure you want to clear all existing products and their results?", vbYesNo, "Delete Products?")
If msg2 = 6 Then
Worksheets("Input Record").Activate
Range("E3:BU98").Select
Selection.ClearContents
Worksheets("Results record").Activate
Range("E3:CA23").Select
Selection.ClearContents
Worksheets("Input Page").Activate
End If
End Sub

View 2 Replies View Related

Clear Data In Multiple Worksheets

Aug 29, 2008

is there a way to clear data in all worksheets according to the ranges specified in the code below, I have around 34 worksheets in which i need to clear data and i dont want to write the below code 34 times.


Sub Clear()

With Sheets("Rec")
.Range("A7:C7").Clearcontents
.Range("E7:O7").Clearcontents

End With

End Sub

View 9 Replies View Related

Clear Numeric Input From All Worksheets

May 26, 2006

I'm trying to create code that will clean up a budget template of numeric inputs so it can be reused. This is as close as I can get but the code still isn't right.

[HTML]Sub ClearSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas, 21).ClearContents
Next ws

End Sub[/HTML]

View 3 Replies View Related

Clear Used Range

Feb 21, 2010

I have a table on a worksheet and have for quite some time used a very successful macro UsedRangeClear. I found here on the forum. Anyway the macro still works on all tables on all other sheets except this one. This is the reason, somehow someone, maybe even me, copied something down or formated down to the 1,048,152th row of the worksheet. My workbook has grown from 5000 kb to 11,000 kb.

I have tried to highlight and deleted the rows, highlight and clear contents and the following macros:

Sub UsedRangeClear()
On Error Resume Next
ActiveSheet.Unprotect Password:="myfadra"
Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.UsedRange
ActiveSheet.Protect Password:="myfadra"
End Sub

Sub ReSetTable_UsedRange()
'For ICFMR
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).row

On Error Resume Next
ActiveSheet.Unprotect Password:="myfadra"
Application.ScreenUpdating = False
Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
ActiveSheet.ListObjects("Table7").Resize Range("A1:T" & LR)
ActiveSheet.Protect Password:="myfadra"
Application.ScreenUpdating = True
End Sub

Each option freezes Excel. I am sure there is something easy I am just missing. Soooo, Please offer any suggestions you can think of.

A Loyal Mr. Excel Follower
Alecia

View 9 Replies View Related

Copy Cells / Range From Worksheets Positioned Between Two Worksheets

Jul 7, 2014

Let's say I have a workbook with 7 worksheets named, for example, "Instruction", "Begin", "Worksheet 1", "Worksheet 2", "Worksheet 3", "End", and "Data". (in that order)

What I want to do is run a macro to go to whatever worksheet that is in between "Begin" and "End" and copy, for example, cells $C$1:$D$10; then paste as formula into worksheet "Data" starting from cell C1 and then down a list (i.e., copied cells from "Worksheet 1" get pasted as formula into "Data" cells C1:D10; then copied cells from "Worksheet 2" get pasted as formula into "Data" cells C11:D20, and so on and so forth).

But if I were to add more worksheets (e.g., "Recipe" and "ToDo") positioned in between "Begin" and "End" and run the macro again, it'll either 1) re-copy all the formulas from the included worksheets back into "Data" including the formulas from the newly added/placed worksheets or 2) it'll add the formulas from the newly added/placed worksheets and paste into "Data" at the end of the list.

Can create the macro to run based on the position of worksheet, and not based on the name of worksheet, since ultimately there will probably be over 10 worksheets between "Begin" and "End".

View 4 Replies View Related

Excel 2010 :: Create Macro Button To Clear Multiple Cells On Multiple Worksheets?

Jul 2, 2014

I have attached a test workbook excel 2010 (ignore ref# errors, I've cut the workbook down for uploading purposes) What I would like to do is have a 'Button' on my 'information Sheet' which when clicked would clear certain cells. I have searched the forum but can't find a solution, everyone seems to want to delete rows or columns but I just want to clear certain cells. The workbook will have 11 sheets each named 'caravan 1' through to 'caravan 11' The uploaded test workbook only only has 3 sheets.

On 'caravan 1' (which is slightly different to the other 10) I want to clear the content of cells

B4 & B5
C4, C22 & C41
D4 & D5
E4,E5, E22,E23,E41 &E 42

On all other 'Caravan sheets' I want to clear the contents of cells

D4 & D5
E4, E5, E22, E23, E41 & E42

It would be icing on the cake if it could give a warning such as " are you sure you want to clear these cells" but that isn't really necessary. The worksheets will be password protected, but the cells mentioned above will not be. If it proves too difficult to clear all the cells on all the sheets with one click, then perhaps a simpler solution might be to have a button on each sheet instead

View 8 Replies View Related

Clear Range With Variable?

May 8, 2014

I need a simple VB Code to clear the cell :

K106 = BI210:BU269

Need to clear the range BI210:BU269

if K106 = BI271:BU341 then need to clear range BI271:BU341

View 2 Replies View Related

Clear Autofilter Range

Nov 28, 2006

I'm wrinting a macro to copy specific data from a table. To do that I'm using a Autofilter and a list of criteria. The macros works fine for existent data, I'm mean, when the result of the filter is not null, but when the filter doesn't find a result, instead of clearing the filter range, it keeps the last valid. The result is a colapse and freeze the Excel. I'd like to know how can I reset or clear the filter range?
The code I'm using is:


Sub Filter_01()

'Definições preliminares
Dim rng As Range
Dim rng2 As Range
Dim ARLE
Dim filter_valid, filter_invalid As Variant

filter_valid = Array()
filter_invalid = Array()
'Criação do Arquivo de Destino
Caminho = "D:Documents and Settingscjcs.ABMeus documentosAutomaSIPPPlanilhas"
Nome_Arquivo = "Produtos_Tanques.xls"
Nome_Completo = Caminho & "" & Nome_Arquivo ...

View 9 Replies View Related

Clear Variable Range

Aug 31, 2007

why the first version below works but the second doesn't

1st

ThisWorkbook.Worksheets("GBP%"). Range(Cells(8, c), Cells(z, c)).ClearContents

2nd

Worksheets("GBP%").Range(Cells(8, c), Cells(z, c)).ClearContents

c = 16 (uses a for statement to go through columns 16 to 111)
z = in this case 24, but is dynamic depending on number of files in a list

Currently using Windows 2000 with office 2000

View 6 Replies View Related

Clear Range On Another Sheet

Apr 18, 2008

I have used the VBA and it works to select all data but I have an issue when there is no data to select beneath the column header. I am running this on multiple worksheets which vary with data week to week.

Sheets("sheet1"). Range("A6:G" & Range("G" & Rows.Count).End(xlUp).Row).Offset(0, 0).Select selection.ClearContents

How can I run this and not have it delete the column header when there is no data? Is there a way to change the formula so that it selects all cell columns of data without defining it?

View 8 Replies View Related

Clear Set Range Variable

Jun 18, 2008

is it possible to clear the value in a range variable?

For example say:

Set A = Range("B4")

Is there a way to clear the value of that range, in other words make it blank again? And unfortuanlly i can't just make it equal to another range i need it to be blank.

View 6 Replies View Related

Clear Column Data With Range

Jun 15, 2014

I have

colpaste1 =Range("D2:D2")=BA
colpaste3 =Range("D4:D4")=BC

If Cell D2 = BA and D4= BC, i need VB Code to clear all contents in column BA to BC.

Note: BA and BC are the columns.

View 2 Replies View Related

Fast Way To Clear A Range Of Cells

Jul 8, 2009

This seems to take much longer than I would have expected. Is there anything I can do to speed it up, or is this just something to live with?

View 13 Replies View Related

Clear Contents Of Cells In A Range, LEN=0

Dec 23, 2009

I'm using a macro to copy the results of a formula and paste the values only on another sheet. The result includes lots of "blank" rows. I have another macro to get rid of the empty rows and move the information up.

It's not working because the "blank" rows aren't empty. Even though I paste values only, experimentation shows that the cells that appear blank return a false to the ISBLANK test with a length of 0.

So now I think I need a macro to run after the pastespecial command to look for cells within a range with a length of zero and delete the contents of those cells, but leave alone anything with a length of >0.

I am brand new to the idea of using VBA, but I have successfully cobbled together some stuff and can usually modify things to work.

It seems I need to maybe use some sort of IF statement along with a LEN and ClearContents. I don't want to delete the blank cells, just make them truly empty so that all of my actual data stays where it should, and my delete empty rows macro works correctly.

I did a search and see some info on clearing contents of columns or rows, or clearing contents based on the content of other columns or rows, but I'm unsure of how to tell it to search each cell within a range and clear the contents of 0-length cells to make them truly empty.

View 10 Replies View Related

Macro To Clear Colums In Range

Jun 19, 2009

I am trying to create a marco that clears the columns of a named range if the sum of the cells in the range is zero.

View 3 Replies View Related

Clear Range Based On Shading?

Dec 26, 2013

I need a macro that will clear the contents of all cells shaded white in range c1:c20.

Clear the contents, leave the cells shaded white.

View 1 Replies View Related

Clear Cells In Range That Are Not Numeric

Mar 28, 2007

I am trying to write a macro in excel to clear all cells within a range that are non numeric. I seem to be going round in circles trying to find out how to do this.

I assume I have to use the IsNotNumeric(Target) argument but I can't find how to specify the target within a range.

View 9 Replies View Related

How To Clear A Range Of Formula Quickly

Jul 13, 2007

I want to clear the range A10:IV65536 or all the cells containning numbers under the row A10.

Right now it takes for ever to clear it mannually because excel recalculates everything... i have over 100 000 data and id like to find a way to delete them quickly.

Is there a way to clear a range without excel recalculating everything???

If not the best way i think would be to clear the last columns first all the way to the first columns.

View 9 Replies View Related

Clear Contents Based Upon Value In Row Range

Jul 21, 2006

I'm trying clear the contents of a column range when the cell above this column range is empty. I know how to do this for one cell, but I would like it to work for a rangefrom R15:BB15.

If IsEmpty(Range("r15")) Then
Range("r16:r35").Select
Selection.ClearContents
End If

End Sub

View 5 Replies View Related

Clear/Delete Zeros In Specified Range

Aug 22, 2006

i need a macro that will select 0's in columns h-j.

View 7 Replies View Related

Clear Contents Of Filtered Range

Jan 10, 2007

I am filtering column S in a sheet to show all rows with a date after the end of the previous month - i.e. >= 01/01/07. What i want to do is clear the contents of those visible cells in column S. I tried the code below (got it on this site) but it works its way up from the bottom of the sheet until it finds the first visible row and then clears the contents of column S in each row above it, whether it is visible or not.

Sheets("Planning").Select
With Range("e2:C2")
.AutoFilter field:=5, Criteria1:="<=" & Sheets("Filtered Statistics").Range("c3")
.AutoFilter field:=19, Criteria1:=">=" & Sheets("Filtered Statistics").Range("d3")
For i = Range("s65536").End(xlUp).Row To 3 Step -1
If InStr(1, ">=" & Sheets("Filtered Statistics").Range("d3"), Cells(i, 19).Value) = 0 Then
Cells(i, 19).ClearContents
End If
Next i
.AutoFilter field:=19
End With

View 2 Replies View Related

Clear, External Data Range..

Jan 11, 2007

I found a way to import some data from some csv files, and it works well for me. I don't want to keep the option to refresh the data. I can go into each tab created from each import and and uncheck the box Data>Import External Data>Data Range Properties>"save query definition" that removes it for me. Is there a way to do that with code. It doesn't work with the macro recorder.

Sub ImportOnline()
On Error Resume Next
Dim DayFile As String
DayFile = InputBox("Enter Date of File (MMDDYY)")
Sheets.Add
ActiveSheet.Select
ActiveSheet.Name = "B-" & DayFile
Application.ScreenUpdating = False
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:My DocumentsB-" & DayFile & ".txt", _
Destination:=Range("A1"))
.Name = DayFile
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False................

View 3 Replies View Related

Clear Named Range & Columns To Right

Sep 17, 2007

I have a dynamically named range the contents of which I want to clear. However, I also want to clear the cell contents in the next column beside the range. So if my dynamically named range is A20:B40 can I clear the contents of A20:C40 without changing the initially named range. Background: The data I have is the result of an advanced filter. The range is named for printing purposes without the final column.
If I then change one of the raw data I want to run the filter again. To do this I need to clear the first filter.

Range("AIT_Change_Management").ClearContents

View 7 Replies View Related

Clear Numeric Cells In Range

Jan 19, 2008

I am trying to code a command button to clear a range of cells if any of them contain a numeric value. For example. If any cells of cell range A1:C10 contain a numeric value then they would be cleared. Not all the cells in the range but only thouse contaiing numeric values. I have tried various methods with not-so-good results.

View 9 Replies View Related

Clear Range Using Variable Row Numbers

May 5, 2008

is it possible to refer to ranges by using index numbers?? I am looking for something like: (which I tried but does not work..)

Worksheets("Sheet1").Ranges("Cells(counter,1):Cells(counter+10,10)").ClearContents

View 4 Replies View Related

Clear Formulas In Specific Range

Jun 6, 2008

For various reasons I need to copy a the range "a2:s251" in the sheet "FWD Input" to another sheet but I need to remove any formulas.

To do this I have used the

Sheets("FWD Input").Range("A2:S251").SpecialCells(xlCellTypeFormulas).ClearContents

This works fine if there are formulas in that range, however if there aren't it gives me: " Run time error: 1004 No cells were found"

So I think I need some code that counts the number of cells in the range with formulae in them and either goes ahead if there are some or quits if there aren't.

View 3 Replies View Related

Find Multiple Strings And Clear Corresponding Range?

May 17, 2008

I am currently trying to write a macro that will search a column for different strings. These strings are inside the cell (as in it is not the only value in the cell) and then copy the entire cell over to another column, then delete the two cells to the right of the originally found cell.

Heres an example of what I want to:

There are four columns, the first has a name with both the first and last (amanda white)the second just the first name (amanda), the third just the last name(white), and the forth an organization name. if the first column contains an organzation name, it has to clear out the first name and last name columns, and copy the name column to the organization column.

NAME | FIRST | LAST| ORG|
amanda white amanda white
mike jones mike Jones
pizza hut pizza hut

I have a list of organization keywords to search the first column (e.g. enterprise, variety, management, pizza). I want it to recongnise the "pizza", copy that entire cell over to the organization column and delete the first name and last name for that row.I've been trying to modify a code like this but i can't seem to make anything work.

VB:
FindWhat = "pizza"
For Each Cell In Range("B2", Range("B" & Rows.Count).End(xlUp)) [code]....

View 5 Replies View Related

Macro To Clear Range In Specific Sheets

Apr 27, 2014

Looking to code a loop to go to sheets whose names begin with "day" and a number and clear a specific range. How would i code this without affecting the other sheets in the book?

View 3 Replies View Related







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