Clear cell contents based on color? - excel

Is it possible to clear a large number of cells contents based on color alone? I don't think that simply filtering is going to work well on this because the dataset is large and 'wide'

If you don't need this done programatically, it can be faster to just use Find and Replace (Ctrl-H).
Press Ctrl-H
Click Options > >
Click the top Format... button to search for for colored cells (use the Fill tab)
Leave the Replace with field blank to delete the contents of cells with the format you specified.

This will clear the content of any cell within the range A1:G8 filled with yellow (65535). Change the color for your color and the range for your range. This is kind of crude, sorry.
Sub Macro1()
Range("A1:G8").Select
For Each Cell In Selection
If Cell.Interior.Color = Excel.XlRgbColor.rgbYellow Then
Cell.Clear
End If
Next
End Sub

You can clear cells by background color using Excel's filter options.
For Excel 2013 & 2010
Open a worksheet where each column has a header row.
Enable column filtering with Data -> Sort & Filter -> Filter
Click the drop-down-arrow on a column, go to Filter by Color, and select a color you want to view. (Any non-colored cells will be hidden)
Select the remaining cells, right-click and select Clear Contents.
To unhide the remaining cells, disable column filtering with Data -> Sort & Filter -> Filter

Related

Conditional formatting with cell values based on their row

I'm currently doing a small side project where I'm converting images into excel spreadsheets. I have a python program which turns each cell into a range between 0 and 255 (RGB color codes).
I had made this a while back and don't actually remember how I colored each row with conditional formatting.
Essentially, I need to select each row, turn it a shade of red. Then I need to select each alternate row (MOD 2 = 0) and turn each of those into a shade of green. Finally, I need to select each third row (MOD 3 = 0) and turn those into a shade of blue.
Again, to reiterate, I'm having trouble with actually selecting the rows. Is there any way I can do this (without doing it by hand)?
Check the following:
Highlight rows to get formatted
Click on "Conditional Formatting" and then "New Rule"
Click the last option on the upper part of the box "Use a formula to determine which cells to format"
Type this =MOD(ROW(),1)=0
Click "Format" and select a fill color (Red in this example)
Repeat it two more time for the other two colors
=MOD(ROW(),2)=0 for Green & =MOD(ROW(),3)=0 for Blue
check the below image

Excel code to link range cells' colour into another

I am building a residential stacking plan in which each cell = unit type with specific color given conditional formatting.
2 tables follow below for each unit reflect a sqm size and a $ value.
I need to reflect only the cells' color into the following tables.
I need a dynamic solution and would prefer avoiding vba (since I'm not proficient), but will use if necessary. Thanks in advance!
Find Image HERE
Set up your Conditional formatting as normal on the first table like this:
Note my table starts at cell C4 but yours is in a different place and should be adjusted accordingly. make sure you DON'T have the $ symbol on the formula in the rule but you do have it on the 'Applies to' section
Now copy and paste this formatting onto the second table.
Finally edit the formulas in the conditional formatting so that they point to the starting cell of the FIRST table. It should look like this:
Note that the formatting 'Applies to' the second table but refers in the Formula to the values in the first table.
The result is this:
You can repeat this for other tables if you need to.
As you are working in Excel 2003(!), follow the following steps:
Select the cells in the second table.
In the menu, choose Format - Conditional Formatting.
In the Conditional Formatting box, choose Formula Is.
In the text box, enter the cell reference of the FIRST table (eg C4="4+"), do not enter any $ symbols.
Click the Format button and select the background fill to match the one in the first table.
Add the other conditions in the same way by clicking the Add>> button.
If you change the color code values (B21:B26) from 2 rooms to 2 (to match your second table), the following should do the trick. Basically, this code is not using conditional formating. Getting the color from conditional formating can be somewhat laborious and tricky (google "excel vba find color conditional formatting"). Instead, the present code reads the color in your Color Code cells, and apply it to the other two ranges.
Private Sub BckgndColor()
Dim ColorCodeRange As Range
Dim NoOfRooms As Range
Dim CellColorIndex As Integer
Dim c As Range
Dim d As Object
Set ColorCodeRange = Worksheets("Sheet1").Range("B21:B26")
Set d = CreateObject("scripting.dictionary")
'Add the pairs (value, color) to dictionary
For Each c In ColorCodeRange.Cells
d.Add c.Value, c.Interior.ColorIndex
Next
Set NoOfRooms = Worksheets("Sheet1").Range("M25:V36") 'Here the range of Table 2 (M25:V36 in your example)
'Scan range, and assign color
For Each c In NoOfRooms.Cells
If d.Exists(c.Value) Then
c.Interior.ColorIndex = d(c.Value)
c.Offset(16, 0).Interior.ColorIndex = d(c.Value) 'If Table 3 is always 16 rows down, this shoud work
End If
Next
Set d = Nothing
End Sub
I gave the option data validation list in sheet 2, while I selecting the option by list the cells will change . for that cells I want to get color also from source table in sheet1 to sheet2 .

Customize Conditional Formatting in Excel 2010

I'm unable to create a rule in Conditional Formatting for this requirement. I was tried using this option "Use a formula to determine which cells to format" inside the rule but didnt get proper formulae.
My Requirement:
If I change the Activity value to Completed in column A then accordingly the font color should be in (Sky blue) and font size is (10) in columns B and C.
If I change the activity value to Delayed in column A then the font color should be in (Red) and font size is (Default or no change) in columns B and C.
Also if I manually type to change the Activity type from To Do to Completed then the Final Date column field value should be automatically filled with the current or Today's date which is as on date.
What formulae I can use for this requirement? How?
Changing the text format is easy to solve with Conditional Formatting, changing the cell's text to today's date requires VBA.
1. Text format
Select cells B2:C10
Create a conditional format with "Use a formula to determine which cells to format". Enter this formula:
=$A2="Completed"
Click the 'Format' button and apply the blue text color and your desired font size.
Repeat the steps using this formula:
=$A2="Delayed"
Apply the red font color.
2. Enter today's date via VBA
Open the VBA editor with Alt+F11
Double click the worksheet on the left hand panel where your Activity table is placed (i.e. Sheet1).
Enter this code in the right hand code panel:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Value2 = "Completed" Then
Cells(Target.Row, 3).Value = Date
End If
End Sub

Excel Filter Where Columns are different

I have two columns in an excel worksheet. I want to filter where the two columns are different. Any advice?
or even more simply put this in the third column
=A1=B1
You could add a calculated column like =A2=B2 and filter for FALSE on that column.
Here's an alternative that only requires formatting the differences...
1) Select the two columns you want to compare and press [Ctrl+\] (or goto special|row differences). If you want to remove the column heading from the selection press [Ctrl+Shift+\] (or goto special|column differences). See example below
2) Format the selected cells with a font color then right-click the selected cell and choose Filter > Filter by selected cell's font color:
Put this in a third column
=if(A1=B1,1,0)
filter where that thridcolumn=0

Add common prefix to all cells in Excel

I have a column with some text in each cell.
I want to add some text, for example "X", at the start of all cells. For example:
A B
----- >>>> ----
1 X1
2 X2
3 X3
What is the easiest way to do this?
Type this in cell B1, and copy down...
="X"&A1
This would also work:
=CONCATENATE("X",A1)
And here's one of many ways to do this in VBA (Disclaimer: I don't code in VBA very often!):
Sub AddX()
Dim i As Long
With ActiveSheet
For i = 1 To .Range("A65536").End(xlUp).Row Step 1
.Cells(i, 2).Value = "X" & Trim(Str(.Cells(i, 1).Value))
Next i
End With
End Sub
Select the cell you want to be like this,
Go To Cell Properties (or CTRL 1)
under Number tab
in custom
enter
"X"#
Select the cell you want to be like this, go to cell properties (or CTRL 1) under Number tab in custom enter "X"#
Put a space between " and # if needed
Select the cell you want,
Go To Format Cells (or CTRL+1),
Select the "custom" Tab, enter your required format like : "X"#
use a space if needed.
for example, I needed to insert the word "Hours" beside my numbers and used this format : # "hours"
Enter the function of = CONCATENATE("X",A1) in one cell other than A say D
Click the Cell D1, and drag the fill handle across the range that you want to fill.All the cells should have been added the specific prefix text.
You can see the changes made to the repective cells.
Option 1:
select the cell(s), under formatting/number/custom formatting, type in
"BOB" General
now you have a prefix "BOB" next to numbers, dates, booleans, but not next to TEXTs
Option2:
As before, but use the following format
_ "BOB" #_
now you have a prefix BOB, this works even if the cell contained text
Cheers, Sudhi
Michael.. if its just for formatting then you can format the cell to append any value.
Just right click and select Format Cell on the context menu, select custom and then specify type as you wish... for above example it would be X0. Here 'X' is the prefix and 0 is the numeric after.
Hope this helps..
Cheers...
Go to Format Cells - Custom. Type the required format into the list first. To prefix "0" before the text characters in an Excel column, use the Format 0####. Remember, use the character "#" equal to the maximum number of digits in a cell of that column. For e.g., if there are 4 cells in a column with the entries - 123, 333, 5665, 7 - use the formula 0####. Reason - A single # refers to reference of just one digit.
Another way to do this:
Put your prefix in one column say column A in excel
Put the values to which you want to add prefix in another column say column B in excel
In Column C, use this formula;
"C1=A1&B1"
Copy all the values in column C and paste it again in the same selection but as values only.
Type a value in one cell (EX:B4 CELL). For temporary use this formula in other cell (once done delete it). =CONCAT(XY,B4) . click and drag till the value you need. Copy the whole column and right click paste only values (second option).
I tried and it's working as expected.

Resources