基于第一个字的条件格式 [英] Conditional format based on the first word

查看:141
本文介绍了基于第一个字的条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Alba Botanica Hawaiian Hand + Body - 24 oz. - Replenishing Cocoa Butter
Alba Botanica Very Emollient Body Lotion - 32 oz. - Unscented Original
Aveeno Active Naturals Daily Moisturizer - 2 x 4 oz.
Aveeno Active Naturals Daily Moisturizing Lotion - 2 x 18 oz.
Aveeno Clear Complexion Favorites - 6 oz. Cleanser + 4 oz. Moisturizer
Cetaphil Moisturizing Lotion - 40 oz. - For All Skin Types
Clean & Clear Daily Skincare Essentials - 20 oz. - Cleanser + Moisturizer
Everyone Lotion For Every Body 3in1 - 32 oz. - Coconut + Lemon

这是我的产品列表,我试图有条件地格式化,具有不同第一个单词的行具有不同的颜色。

This is my list of products, I'm trying to conditionally format so that each row that has a different first word has a different color. How do I do that?

推荐答案

这不完美,但可能已经够了。

This is not perfect, but may be enough.

您可以使用第一个 x 字母ascii代码创建数字半唯一ID,然后使用它来对单元格进行着色。这可以通过两种方式完成,但是首先要创建一个新的列(帮助列),然后在第一个单元格中粘贴以下公式:
CODE(LEFT(B1,1 ))+ CODE(MID(B1,2,1))+ CODE(MID(B1,3,1))+ CODE(MID(B1,4,1))+ CODE(MID(B1,5,1)) + CODE(MID(B1,6,1))

You can use the first x letters ascii code to create a numeric semi-unique ID, and then use it to color the cells. This could be done in 2 ways, but both start with making a new column (a "helper column") and paste the following formula at the first cell: CODE(LEFT(B1,1))+CODE(MID(B1,2,1))+CODE(MID(B1,3,1))+CODE(MID(B1,4,1))+CODE(MID(B1,5,1))+CODE(MID(B1,6,1))

这将转换每行的前6个字符(列 B )到ascii代码,并总结。如果6个字符不足,您可以通过添加 + CODE(MID(B1,x,1)),其中 x 是越来越多的数字。

This will convert the first 6 characters of each row (in column B) to ascii code, and sum them. If 6 characters are not enough you can use even more by adding +CODE(MID(B1,x,1)) where x is an increasing number.

将这个药物贴到所有的列后,你会得到这样的东西:

After drugging this to all the column you'll get something like this:


  1. 使用条件格式的颜色范围:

这是更简单快捷的方式,可能更适合您的需求,然后另一个。只需在第一列使用范围颜色条件格式,您将获得基于每行中第一个单词的颜色:

This is the more simple and quick way, and may be even more suitable to your needs then the other one. Just use the range-color conditional formatting on the first column, and you will get a color based on the first word in every line:


  1. 使用颜色索引和VBA

上述解决方案不会对所有行进行颜色处理,如果这对您很重要,可以尝试添加另一个具有以下公式的帮助列:

The above solution does not color all the line, and if this is important to you, you can try adding another helper column with the formula:

= A1 / MAX(A:A)* 54

其中 A 是第一个帮助列。那么你可以使用这个VBA代码:

Where A is the first helper column. Then you can use this VBA code:

Sub format_text()
    Sheets(1).Select
    RowCount = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 3 To RowCount
        Cells(i - 2, 3).Interior.ColorIndex = Cells(i - 2, 2).Value + 2
        Next
    End
End Sub

颜色列 C (现在是文本列),Excel中的预设颜色的3-56之间的颜色索引(1& 2是黑白):

to color column C (which is now the column with the text) with a color index between 3-56 of preset color in Excel (1 & 2 are black and white):

您可能会发现不是全部颜色是可读的,但有效的颜色编码有限制(约为7种颜色),因此这是问题的固有问题。

You may find that not all the colors are readable, but there is a limit to an effective color-coding (and it is about 7 colors), so this is an inherent problem of the question.

告诉我是否解决了这个问题;)

Tell me if it solved the problem ;)

这篇关于基于第一个字的条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆