Clear Cells In A Range Based On Other Cell Values

Jun 6, 2012

I have two rows of numbers, say D1 to F1 and D2 to F2. Row D2 to F2 will always have lower values.

The range below it is D3 to F100. I want the range to clear the contents of the cells in the range where:

a) the cell is > the x1 cell above it

OR b) the cell is < the x2 cell above it

If it is = or between the two cells, the value stays.

Example:

If D1 thru F1 is 4, 5, 7 and D2 thru F2 is 2, 4, 3, then:
D3 is 5, it is cleared
E3 is 4, it stays
F3 is 5, it stays
D4 is 2, it stays
E4 is 1, it is cleared
F4 is 9, it is cleared
Etc

Basically, the cell in the range looks up its own column, compares itself to x1 and x2 in that column. If it's greater than or less than, then it clears the contents, if not, the value in the cell stays.

View 3 Replies


ADVERTISEMENT

Clear Cells Of Values Based On Cell Selection

Jun 13, 2008

A project I am working on calls for me to implement a macro that will clear the contents of a cell (but not affect the validation list it contains) based on the selection of another cell or cells. So on the simplified attached example, I need to achieve the following;

On the fist row of options, if cell "C3" is selected, then the contents in cell "D3" are cleared. If cell "B3" is selected then the contents in cells "C3" AND "D3" are both cleared. Similar is needed for the second row of options;

If Cell "C6" is selected, then the contents in cell "D6" are cleared. If cell "B6" is selected then the contents in cells "C6" AND "D6" are both cleared. Finally, if cell "A3" is selected, then ALL of the above cells' (B3-D3 & B6-D6) contents must be cleared.

View 7 Replies View Related

Clear Contents Of Range Based Upon Values

Dec 17, 2007

There is data(numerical) or blanks in each of the cells in the range H32:O37

I want to clear the contents if they are a duplicate of the previous line.

Looking for a macro hopefully. Found many to delete the whole row but just the specific range based upon the duplicate criteria..As there is data surronding that area do not want to delete whole row just clear that specifc area.

H32:O32 clear contents if same as H31:O31 if any valuse are different then stays the same
H33:O33 clear contents if same as H32:O32 if any valuse are different then stays the same
H34:O34 clear contents if same as H33:O33 if any valuse are different then stays the same
H35:O35 clear contents if same as H34:O34 if any valuse are different then stays the same
H36:O36 clear contents if same as H35:O35 if any valuse are different then stays the same
H37:O37 clear contents if same as H36:O36 if any valuse are different then stays the same

View 9 Replies View Related

Clear Contents Of Cell Based On Comparsion Of Cell Values

Mar 7, 2007

I am a financial administrator & every month I have down load 4 bank accts as CSV, import into xl & code (CACode) the amounts for our accountant. I have VBA that formats, adds headings & formula etc but I have a problem/s. In H col I place CAcode & I use a sumif formula in I col to sum all the amounts with that have the same CAcode. For simplicity sake I copy the sumif down & then sort H col ascendindingly (this is done by VBA). Now I am trying write a macro to clear the contents of the cell in I col

if eg h60 = h59
then I60 clearContents, Select h59
Else select H59
Do until H3 is selected

Psuedocode
Select table (A2:I Xldown)
Sort Table by CAcode (H Col)
Set Range as H3:Xldown
Select Last cell with CAcode (Xldown) in H col
For every cell in Range (H3:Xldown)
Use If/thenIf Last cell = 2nd Last cell (H Col) then
Clear contents of I col (last row)
select 2nd Last cell (H Col)
Else 2nd Last cell (H Col)Next Cell

I have to use Xldown to select range as the range will be variable each month & for each bank acct. I need to clear contents of cell to verify that all the sub-totals of unique CAcodes of the CAcoded amounts = the totals Because I may have up to 120 rows X 3 bank accts I am slowly using vba to do my work.

Sub sort_And_delete_Sumif_amounts()
Dim r As Range
'Select range to sort
Range("A2:I98").Select
'Sort CAcode in H col ascendingly
Selection.Sort Key1:=Range("H2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'select range for comparisomn of CAcode
Set r = Range("H3", Selection.End(xlDown))................

View 4 Replies View Related

Automatically Clear Range Based On Cell Criteria

Jan 9, 2007

I have the following Worksheet Change Event in my worksheet. The contents of range rng are not cleared.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range

rng = Range("F" & Target.Row & ":M" & Target.Row)

If Not Intersect(Target, Range("N5:N1000")) Is Nothing Then

If Target.Cells.Count = 1 Then

If Target.Value = "Yes" Then

Application.EnableEvents = False

rng.ClearContents

Application.EnableEvents = True

End If

End If

End If
End Sub

View 9 Replies View Related

Conditional Format Color Of Cell Based On Values In Range Of Cells?

Oct 24, 2013

I would like to format the color of cell A1 on Sheet 1 based on true or false values from cell range A1:A10 on sheet 2. For instance:

1. If all cells on sheet 2 in range A1:A10 were false then cell A1 on sheet 1 would be red.

2. If some cells on sheet 2 in the range A1:A10 were false and some were true then cell A1 on sheet 1 would be yellow.

3. If all cells on sheet 2 in range A1:A10 were true then cell A1 on sheet 1 would be green.

View 5 Replies View Related

Copy And Paste Range Of Cells Based On Number Of Cell Values In Column A

Mar 17, 2014

Please see attached sample worksheet. Column A will be generated by the user manually.

I'm looking for a way in VBA to have A1:D20 in Sheet2 copied and pasted in the "Bank Reconciliation" Sheet based on how many "Markets" there are in Column A. Then, once that's complete to have A22:D30 (the smaller box in Sheet2) copied and pasted directly below those results.

I have what the macro would hopefully generate to the right in "Bank Reconciliation" (B6:E54) as an example. So if there's a market in A1, copy and paste the box to B6. If there's a market in A2, copy and paste the box directly below the first (B26) etc. etc. until it's done, then paste the smaller box directly below whatever the macro generates.

Book2.xlsx‎

View 3 Replies View Related

VBA - Copy Range With Multiple Same Values Based On Other Cell Values

Aug 31, 2012

I want to build a database where the user can select a specific time period. I have a static file with the time periods and the related values. For instance I have in column A1:A15 the time periods from January 2011 to Dezember 2011, but I have some dates multiple times as there are more values attached to it. For instance I have in the first 4 rows January 2011...what I want is when someone puts in the value January 2011 in cell B1 and Dezember 2011 in cell B2 that the whole static file gets copied to another location (including the multiple dates) displaying the chosen time period. Similarly if someone puts in the value March 2011 to November 2011, I want only those values to be copied.

View 4 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 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 Cells With Duplicate Values

Dec 10, 2013

Checked for a while now for a match in my query but can't find one that matches. I have a column of data to which has multiple values in each cell separated by a comma I.e 1,1,12,37

I copy this column into a new sheet a:a then I'll run text to columns to separate the values into there own cells so the following columns now show this

a1 =1 b1=1 c1=12 etc

I'm now stuck as I need to clear the contents on the cells within range a1 to k1 that have duplicate values.

end result is a1=1 b1 is now blank c1 =12 etc

View 6 Replies View Related

Conditional Clear Based On Other Worksheet Range

Nov 5, 2008

I have a range on worksheet "CONTROL" from S129:S228. There are 100 rows there. I have another range on the active sheet from B17:N116, also 100 rows. If S129 has a value of 1, then I need row 17 on the active sheet to be cleared (columns B-N). And so on all the way to the bottom of the ranges. If it has no value in the cell, then no clearing takes place. So it needs to test the whole range at once. I really have no clue what the variants and ranges should be, and have NO CLUE how to define a variable range so that I can use the value that R is on in the testing cycle to tell the active sheet which row to delete.

View 3 Replies View Related

How To Select Range And Clear Based On LR Variable

Jul 28, 2008

I want to select and clear a part of a sheet.

here is what I have.

Sub clear_data()
sheets("sheet1").select
lr = activesheet.usedrange.rows.count

Here is where I get lost in translation (syntax).

I want to select starting at Bcolumn through bycolumn but the row be set with the LR from above, since the rows always change.

I could write B2:by2000, but i want to use the LR variable to define the number of rows i have.

View 9 Replies View Related

Copy Or Clear A Range Based On Checkbox

Jan 30, 2008

I am good at excel but an infant with VBA. I have inserted a checkbox onto my worksheet. I want it, when checked, to select a row of data ("k5:k16") from Sheet 1 and copy it to ("a1:a12") in Sheet 5. When the checkbox is unselected, I want the ("a1:a12") to be cleared. I've tried several different ways to copy and continue to run into errors. I know there is a simple solution, but it's beyond me.

View 2 Replies View Related

Clear & Set Print Range Based On Selection

Feb 22, 2008

Is there are macro that will allow me to: Clear Print Area, then Set Print Area based on user selection and finally print the Print Area to fit 1 page? I tried to search for solutions, but couldn't find any that matched my problem.

View 2 Replies View Related

Generating Values In Number Of Cells Based On Adjacent Cell Values

May 22, 2014

What I have In Column B, I have the datesIn Column I, I have engineers name What I need I want a macro to generate Serial Nos. (1,2,3....... n) in column A If an only if the date in column B is today's date and the engineer's name matches with the PC's username

The following is my code

[Code] ....

Above code runs without errors but does nothing.

View 4 Replies View Related

Show / Hide Sheets Based On Values Of Cells In Range?

Sep 11, 2013

I have a workbook wherein I have 7 sheets.Lets say they are called Tom, Peter, John, Sia, Mia, Tia and "Home Page". I have 2 buttons for Report 1 and 2 to which I want to assign the macros.I also have a table wherein I have defined which sheets I want to show. First Column of table has sheet names from A2:A6(Home Page,Tom, Peter, John, Sia, Mia, Tia). Column 2 has report 1 sheets - Home Page, Tom, John, Mia and Column 3 has report 2 sheet names- Home Page, Peter, Sia, Tia

What I want to do is, if I click on "Report 1" button, I only want to show sheets whose names are there in cells under report 1 so for report 1 it will be Home Page, Tom, John, Mia. For Report 2, it will be Home Page, Peter, Sia, Tia. Since I have many reports I want this to be one macro. Stepwise, here is what I want

1. Click on button for Report, macro should check which report I am referring to and select the range on basis of that. Report 1 = column B, if Report 2, Range is column C.
2. Basis the range I want sheets to show or hide.

View 1 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

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

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

Code To Clear Cells In Range Which Are Not Highlighted?

May 15, 2014

Looking for some code to clear cells which are not highlighted

i.e. clear everything from row 2 downwards (Columns I:P) but exclude cells which are highlighted (not conditional formatting)

View 3 Replies View Related

Clear Cells Based On Another Column (renamed For Erik)

Feb 19, 2007

if A7="in" delete contents of Q7
the contents in the a column are "in" or "out"
the contents of the Q column are all different so it will have to be cell based
i will have to apply this to the whole sheet

View 9 Replies View Related

VBA Macro: Clear All Constant Cells In Range That Don't Have Formulas

Jun 22, 2009

is there a way to do this in VBA? I've also read: - Dave Hawley's recommendation of using: Sheet1.UsedRange.SpecialCells(xlCellTypeConstants).ClearContents

from another thread (which is excellent!)

- SHG's recommendation of using a named range, for example:

Range("Inputs").ClearContents

Given my limited knowledge of VBA, how would I now combine the two to write a VBA sub-routine that clears a named range entitled "Entry" on a sheet entitled "Data"? Would the following be the correct syntax: Worksheets("Data").Range("Entry").SpecialCells(xlCellTypeConstants).ClearContents

View 6 Replies View Related

Clear Contents Of Cells Based On Data Validation Selection

Apr 13, 2012

I am trying to find something that would allow me to have a spreadsheet clear the contents of a certain cell based on the selection made from a data validation list which resides on the same row. This can best be described with an example.

The user selects anything but " " or "none" from the validation list, which for this example resides in C5, would trigger code to clear the contents, if any, in AA5. If " " or "none" is chosen the value remains.

This capability should be available for each row through 100.

View 3 Replies View Related

Return Values Based On The Range In Another Cell

Nov 28, 2012

I am trying to put together a calculation sheet for court costs and I need a cell to return a value based on the amount entered in another cell. For example, if I input a value between 1 and 5 in cell A1, I would like "Cat" to appear in cell A2. However, if I input a value between 6 and 10 in cell A1, I would like "Dog" to appear in cell A2. Is this something that can be done without VB?

For the real spreadsheet, I would need the following outputs in cell A2 based on the respective ranges in cell A1:

Output to A2 = $405 if input to A1 is < $50,000.
Output to A2 = $905 if input to A1 is ≥ $50,000 and < $250,000
Output to A2 = $1,905 if input to A1 is ≥ $250,000

View 3 Replies View Related

Splitting Known Range Based On Cell Values?

Feb 5, 2013

I've attached a workbook to explain my query further but essentially I have a data range, variable in size and I would like to split the range based on values in the range (delimiters if you like) into discreet ranges.

RanaldRangeSplit_01.xlsx

View 6 Replies View Related

Assign Range Name Based On Cell Values

Jan 24, 2009

In my workbook sheet 11 has some ranges that need to have names based on cell values in sheet2 (for purposes of data validation lists).

Range S28:S46 will assume the name of sheet2A11 & sheet2A3.
(example name period_1unit_1)

Range U28:U46 will assume the name of sheet2A11 & sheet2A4.

Range W28:W46 will assume the name of sheet2A11 & sheet2A5

Right now I am calling the code when something is entered into A11.

I have tried if statement and select case, but I ran into complications with both.

I have posted both codes with the questions I have concerning those codes.

View 6 Replies View Related

Run Macro Based On Corresponding Cell Values In Range

Feb 13, 2008

I have a range "RangeOne" and i want to check the range row by row.

In each row I want to check for value in second cell. If the value is 10 or more then the entire row in the range should be selected and then execute a macro. If the value is 0 to 10(but not 10 exactly) then the row in the range should be selected and then execute macro2.

View 3 Replies View Related

Excel 2010 :: Clear Contents Of A Range Of Contiguous Cells

Jun 4, 2013

I am trying to clear the contents of a range of contiguous cells (containing formula) in Excel 2010 64bit. But it is taking a LONG time (read >30min to clear a range 288 x 100). Originally was doing it in VBA but it was taking too long so I started stepping through the macro and identified that the slow down was occurring on a particular sheet only. So the problem is in Excel....not VBA because it is still very slow when deleting the same range in Excel without using VBA.

I've tried all the usual suspects including: Application.EnableEvents = False (run from the VBA Immediate window when using Excel without VBA), Setting to Example of slow clear contents5.xlsxExample of slow clear contents5.xlsxManual Calculation, Turning off screen updating, deleting all the conditional formatting on the sheet, removing any data validation from the sheet (yes all these at the same time). There are no links to external workbooks. I've even tried in VBA changing from .ClearContents to .Value = vbNullString. All to NO AVAIL! By way of background the file is about 72Mb #.xlsm.

If I try to clear contents of larger ranges on other sheets in the same workbook it is instantaneous. If I copy the problem worksheet off to a new workbook, I can delete the problem range almost instantly. Why deleting a range of cells should take so long! Again to clarify, I am using the terms "delete" and "clear contents" interchangeably, but they both mean "clear contents" (not delete and move up cells). P.S I've also looked into the reported conflict between Excel and Google Desktop Office Add-in (Office Button->Excel Options->Addins->Com Addins and deselect Google Desktop Office Addin) but I didn't have Google Desktop Office Add-in so it isn't that.

View 6 Replies View Related







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