Adding number to multiple cells in google sheets - without dragging corner or copying background color - google-sheets

I've tried to figure out multiple ways to do this. It seems like it should be simple enough but I haven't been able to figure out how to select multiple cells to fill them with the same number - without changing a preexisting background color that I have across some cells.
If I do the usual select the cell, drag the corner routine, I end up copying the background color in unintentional ways.
I literally just need the same number (.25) assigned to almost every cell.

try:
=INDEX(SEQUENCE(5; 6; 1; 1)*0.25)
where 5 is row and 6 is column

Use this formula
=ArrayFormula(IF(ISNUMBER(RANDARRAY(COUNTA(A:A),COUNTA(1:1))), 0.25, ""))
Explanation
COUNTA(A:A) is the number of columns in the range A:A.
COUNTA(1:1) is the number of rows in the range 1:1 the "header".
You can replace it with hard coded number
Example: 12 columns and 10 rows.
=ArrayFormula(IF(ISNUMBER(RANDARRAY(12,10)), 0.25, ""))

Related

In Google Sheets how do I replicate a range of formulas horizontally?

I have 4 cells with 4 different formulas adjacent to each other horizontally.
If I want to repeat these 4 cells horizontally I need to select and drag them all the way to the end of the sheet every time, and if I add more columns I need to do that again.
Now with just 4 cells it's pretty simple, but I need to do the same with a 4x6 range of cells and I may have to expand this range in the future.
Isn't there a faster solution or a keyboard shortcut to do it?
Edit: https://docs.google.com/spreadsheets/d/1vPTVj_iK6jbt37-iWunH3Zc-9CD8M4QXaoebNA3P9wQ/edit?usp=sharing This is an editable Sheet with the formulas

Counting the Number of Empty Cells between Non-Empty Cells in Google Sheets

I'm trying to count the number of empty cells that exist in a column between each non-empty cell but haven't been able to work out how.
Using this, I'm also trying to find the largest "empty distances" and locate the cell in the center of these distances.
The sheet I'm working with lists a set of marker colors and denotes the ones that are owned out of the full set of colors. I'm trying to find the largest ranges of missing colors and then find the colors in the middle of those ranges in order to find a handful of markers that would best help to fill out the spectrum.
Columns 1-6 are information- Column 7 marks whether the color is owned:
I may have an answer that helps you.
I could only get it to work using a helper column, but someone may know how to eliminate that requirement.
The helper column creates an array, basically listing the row numbers of the rows that have an "x" in your column B.
The main formula then measures the gap between each of these listed row numbers. It also checks the gap before the first "x", and after the last "x". Note that I have the data starting on row 2, which complicates the formula, but makes the sample sheet clearer - this can easily be changed to row 1 if you prefer.
={F2-1;
query(ArrayFormula(if(isnumber(F3:F),F3:F-F2:F-1,"")),
"select Col1 where Col1 > 0",0);
counta(A2:A)-indirect("F"&COUNTA(F$2:F))}
See a sample sheet here:
https://docs.google.com/spreadsheets/d/19QUFGRqTT6BqOsBrEBpTIxQCeNdRa5mzXhxQpCZ8sV4/edit?usp=sharing
Then I used a second formula to calculate the max gap between "x"s, (or before the first or after the last x).
Note that calculating the midpoint of the gaps, and doing a lookup of the corresponding mid-point colour, is something that can be added to this answer, if you share a sample copy of your sheet and share it for editing.
Let me know if this helps. I'll add more explanation to describe what the formula is doing tomorrow.
And I'll provide a second tab with the formulas adjusted to work with data beginning on row 1.
You can also get the lengths of the gaps using Frequency:
=ArrayFormula(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),if((B1:B20="X")*(A1:A20<>""),row(B1:B20))))
but finding the centres of the gaps and allowing for equal-sized gaps is more difficult.
This should find the position of the "X" at the end of the longest gap:
=ArrayFormula(
sum(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))*(sequence(countif(B1:B20,"X")+1,1)<=
match(max(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))),frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20))),0)))+
countif(sequence(countif(B1:B20,"X")+1,1),"<="&
match(max(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))),frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20))),0))
)
and then it should just be a case of working backwards from there to the centre of the longest gap. However the formula needs further refinement to deal with the cases
(1) Where the longest gap is after the last "X"
(2) Where there is a tie for the longest gap
(3) Where there is a need to list the longest, second longest, third longest gap etc.

Highlight if duplicate in cell range

I need a solution to highlight all identical cells in cell range C2:I7 with color background 'green'.
I tried using the =countif and =countifs(C2:I7;C2)>1 and a lot of similar adjustments to this. I can only get it to highlight all but 1 or more of the identical cells.
https://docs.google.com/spreadsheets/d/e/2PACX-1vSfBYKUzCWPCroBKVKACJCrocmPsvjgLcjgF7FDzFTepFcG1YdJx85e39rUaCBSUCqlaHzXPOpUNkPO/pubhtml
You need to lock the range C2:I7
=countifs($C$2:$I$7;C2)>1
Conditional formatting assumes relative addressing. So if you look at the letter D at the end of the second row (I3) for example, the effect of your original formula is
=countifs(I3:O8;I3)>1
and there are no additional D's within that range.

If any number in one range of cells matches a number in another range of cells, highlight them?

I am trying to find a formula for conditional formatting a specific range of cells.
Screenshot
If any number in the yellow cells (B1:K20) matches any number in the green cells (N1:S30), highlight that number in the yellow cells with a background color. There are and will be duplicates in both the yellow and green cells. I made the cells yellow and green to make it easier to explain my problem, normally they are all blank where the highlighted numbers in B1:K20 will have a green background. Numbers range from 1 to 45.
I used to do this by making a new rule in conditional formatting for every unique number in the green cells but that is becoming very tedious as the amount of numbers in the green cells grow larger.
I have experimented for a couple hours with the MATCH formula in conditional formatting but have gotten very odd results, hoping any of the experts here could help.
Please select B1:K20 and try a CF formula rule of:
=countif(sort(unique(query({$N$1:$N$20;$O$1:$O$20;$P$1:$P$20;$Q$1:$Q$20;$R$1:$R$20;$S$1:$S$20}))),B1)
BEWARE This seems unreliable (or just plain wrong?!)
It seems the response lag for changes might be reduced with the array outside the CF formula, so perhaps in say U1:
=sort(unique(query({$N$1:$N$20;$O$1:$O$20;$P$1:$P$20;$Q$1:$Q$20;$R$1:$R$20;$S$1:$S$20})))
and instead for CF:
=countif($U$1:$U$120,B1)

How do I change the row that numbers are compared based on the data in another cell?

I am usually good with conditional formatting in excel/google sheets, but here is my current challenge. I am needing to format specific cells based on the data in a table at the top of the sheet where the row used for comparison changes based on the value in one cell. Here is the link to the sheet I am currently working on.
https://docs.google.com/spreadsheets/d/1t7pgvGjxs1Eb3cCcRnLDA6E9ov5riEDAjn-fX3A0s8I/edit?usp=sharing
-The table at the top of the is the reference table and does not change.
-the number in column E is the data that determines which row of the table to compare the data in columns G through AN
The Situation:
Let's look at Name 3.
The numbers in G18:AN18 are compared to the G12:AN12 because of the matching number in E18 and E12
If the number in G18 equals G12 - no formatting change
If the number in G18 is one less than G12 - fill color Yellow
If the number in G18 is more than one less than G12 - fill color Red
This is true for each cell in row 18 columns G:AN
- That's the easy part -
Now, when the number in E18 changes (from "9" to "10" for example), I need it to stop looking at row 12 and now look at row 13 because E18 now matches E13
I know that I can do it using nested IF/AND statements but I would have to do it for each and every cell individually. How can I do this more easily through google sheets?
You need to use INDEX/MATCH, so for the yellow formatting starting in G16:-
=G16=INDEX($G$4:$R$14,MATCH($E16,$E$4:$E$14,0),COLUMN(A:A))-1
The idea is that as you copy it across the column changes to B:B etc. so you get the next column of the top region and as you copy it down you get whichever row matches E16, E17 etc.
I'm sure you can modify it for the red formatting and also to take account of any blank cells.
Also, in this particular case that the numbers in E4:E14 are just the numbers 1-11, you could use E16:E25 to index directly into G4:R14 and make the formula a lot simpler like this:-
=G16=INDEX($G$4:$R$14,$E16,COLUMN(A:A))-1

Resources