Check if values in a range are the same.

VytautasM

New Member
Joined
Jan 31, 2020
Messages
33
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good day,

Looking for any help on the following problem.

Column A has variables. Column B marks the start and end of a range. Column C must display the variable, if variables in the range are all the same. If not "-".

Not sure if this explanation if clear enough. Any help, thread or tutorial to guide me to the right answer is appreciated.

Thank you.

KITEKAT1.KITEKAT
KITEKAT
KITEKAT
KITEKAT
SNICKERS2.SNICKERS
SNICKERS
SNICKERS
SNICKERS
MARS3.MARS
MARS
MARS
SPRITE4.-
FANTA
FANTA
COCA COLA5.COCA COLA
PEPSI6.PEPSI
PEPSI
PEPSI
PEPSI
PEPSI
PEPSI
PEPSI
PEPSI
PEPSI
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try:

Book1
ABC
1
2KITEKAT1KITEKAT
3KITEKAT 
4KITEKAT 
5KITEKAT 
6SNICKERS2SNICKERS
7SNICKERS 
8SNICKERS 
9SNICKERS 
10MARS3MARS
11MARS 
12MARS 
13SPRITE4-
14FANTA 
15FANTA 
16COCA COLA5COCA COLA
17PEPSI6PEPSI
18PEPSI 
19PEPSI 
20PEPSI 
21PEPSI 
22PEPSI 
23PEPSI 
24PEPSI 
25PEPSI 
267
Sheet9
Cell Formulas
RangeFormula
C2:C25C2=IF(B2="","",IF(COUNTIF(A2:INDEX(A:A,AGGREGATE(15,6,ROW(B3:B100)/(B3:B100<>""),1)-1),"<>"&A2)>0,"-",A2))


Note that I added the 7 in B26 to mark the end of the data. This is to keep the formula simple. I can change the formula if you can't put a value there. This also assumes that your ranges are 100 rows or less. If that's not the case, just change the 100 in the formula (2 places) to some higher value.
 
Upvote 1
Solution
Eric,

Thank you very much. Also a off topic question. My excel knowledge is decent, but when I need something more complex like the formula you wrote I get stuck.

Do you have a any tips, book recommendations, articles that could help me crack the logic, structure of something more difficult ?
 
Upvote 0
I'm glad the formula works for you! :cool:

As far as your followup question, I'm not sure what to tell you. I'm largely self-taught. When I first started frequenting this forum, I thought I knew a lot, only to learn that I really didn't! I ended up reading a lot of the answered questions, and deconstructing those formulas to see how they worked. In time, I figured out some basic tricks, and then learned how to combine different tricks in a new formula. I don't know how to formalize that process so you can follow it. Try Googling "excel formulas cheat sheet pdf". You'll get several links where people have compiled different types of formulas. Even if you don't experiment with all of them, at least read over them to get the gist of it. Later, when you need something, it'll tickle your memory and you can go back and look up the details.

Good luck!
 
Upvote 0
Is it possible to adjust the formula so that blanks in column A are ignored please? The result in col C should be the same but there could be a blank in row 3 for example?
 
Upvote 0

Forum statistics

Threads
1,221,840
Messages
6,162,311
Members
451,759
Latest member
damav78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top