简体   繁体   English

如果一个单元格值等于该值,则另一个单元格等于

[英]If a cell value equals this, another cell equals that

I have a spreadsheet with a column for cities, of which their are only 4 different values. 我有一个电子表格,其中包含城市列,其中只有4个不同的值。 What is the formula for equating a new column to show the corresponding state and apply it to the entire list? 将新列等同于显示相应状态并将其应用于整个列表的公式是什么? Example: 例:

Atlanta equals GA, Phoenix equals AZ, Chicago equals IL, Nashville equals TN 亚特兰大等于GA,菲尼克斯等于AZ,芝加哥等于IL,纳什维尔等于TN

Thanks!! 谢谢!!

You can use the VLookup function for that: 您可以为此使用VLookup函数:

Make a table with your city name in one column and the state in the next column. 制作一张表格,其中一栏列出您的城市名称,下一栏列出州。 Then the following formula next to the city that you want populated: 然后,在要填充的城市旁边添加以下公式:

=VLOOKUP(A1,A$20:B$23,2,FALSE)

In this example, the city you want to identify is in A1, and this formula goes in B1. 在此示例中,您要标识的城市在A1中,而此公式在B1中。 You can copy it down to B2, B3, etc because the table is hard-coded as A$20:B$23, rather than A20:B23 (where each successive copy down the column would look for a table one row down as well). 您可以将其复制到B2,B3等,因为该表的硬编码为A $ 20:B $ 23,而不是A20:B23(在该列下进行的每个后续复制也会在下一行查找表)。 This example put the lookup table in the AB columns, but you could put it anywhere you like. 本示例将查找表放置在AB列中,但是您可以将其放置在任意位置。

The FALSE at the end means, look for an exact match, not closest. 最后的FALSE表示寻找精确匹配,而不是最接近的匹配。 So if you get a "Dallas" in your list, the function will return NA rather than guessing between the state for Chicago and the state for Nashville (either side of Dallas, alphabetically). 因此,如果您在列表中看到“达拉斯”,该函数将返回NA,而不是在芝加哥州和纳什维尔州(达拉斯市的任一侧)之间进行猜测。

Hope that helps! 希望有帮助!

EDIT: You added that you also need zipcode info, and that's easy enough to add. 编辑:您添加了,您还需要邮政编码信息,并且添加起来很容易。

Your table that defines everything would put the zipcode in the 3rd column, so down at A20:B23 (in my example above) you'd end up with A20:C23, where the table would look like 定义所有内容的表会将邮政编码放在第三列,所以在A20:B23(在上面的示例中)中,您将得到A20:C23,该表看起来像

Atlanta   GA   12345
Chicago   IL   23456
Nashville TN   34567
Phoenix   AZ   45678

The cell next to your city in the table you want to populate would be in B1 as shown above giving the state, and then in C1 you'd have the following formula: 要填充的表格中城市旁边的单元格将在B1中,如上所示,给出州名,然后在C1中,您将具有以下公式:

=VLOOKUP(A1,A$20:C$23,3,FALSE)

The changes are that here the table is defined out to column C, and instead of "2" returning the second column (ie the state abbreviation shown in B), it returns the zipcode shown in column C, the third column. 所做的更改是,在此表已定义到C列,而不是返回第二列(即B所示的状态缩写)的“ 2”,而是返回C列第三列的邮政编码。

Again, hope that helps. 再次希望对您有所帮助。

由于您提到“仅4个不同的值”,因此可能是:

=CHOOSE(MATCH(LEFT(A1),{"A","P","C","N"},0),"GA","AZ","IL","TN")

You can use a VLOOKUP Table that contains the city and state abbreviation. 您可以使用包含城市和州的缩写的VLOOKUP表。

Here is a table that has the Capital, State, State Abbreviation. 这是具有大写,州,州缩写的表格。

Montgomery  Alabama AL
Juneau  Alaska  AK
Phoenix Arizona AZ
Little Rock Arkansas    AR
Sacramento  California  CA
Denver  Colorado    CO
Hartford    Connecticut CT
Dover   Delaware    DE
Tallahassee Florida FL
Atlanta Georgia GA
Honolulu    Hawaii  HI
Boise   Idaho   ID
Springfield Illinois    IL
Indianapolis    Indiana IN
Des Moines  Iowa    IA
Topeka  Kansas  KS
Frankfort   Kentucky    KY
Baton Rouge Louisiana   LA
Augusta Maine   ME
Annapolis   Maryland    MD
Boston  Massachusetts   MA
Lansing Michigan    MI
Saint Paul  Minnesota   MN
Jackson Mississippi MS
Jefferson City  Missouri    MO
Helena  Montana MT
Lincoln Nebraska    NE
Carson City Nevada  NV
Concord New Hampshire   NH
Trenton New Jersey  NJ
Santa Fe    New Mexico  NM
Albany  New York    NY
Raleigh North Carolina  NC
Bismarck    North Dakota    ND
Columbus    Ohio    OH
Oklahoma City   Oklahoma    OK
Salem   Oregon  OR
Harrisburg  Pennsylvania    PA
Providence  Rhode Island    RI
Columbia    South Carolina  SC
Pierre  South Dakota    SD
Nashville   Tennessee   TN
Austin  Texas   TX
Salt Lake City  Utah    UT
Montpelier  Vermont VT
Richmond    Virginia    VA
Olympia Washington  WA
Charleston  West Virginia   WV
Madison Wisconsin   WI
Cheyenne    Wyoming WY

Then you would use =VLOOKUP(A1,A1:C50,3, FALSE) to look for A1 (Montgomery) in the table and it would output AL for example. 然后,您将使用=VLOOKUP(A1,A1:C50,3, FALSE) )在表中查找A1(蒙哥马利),例如,它将输出AL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果单元格等于另一个单元格中的值,则cellX - If cell equals with a value in another cell then cellX 如果第 7 列中的一个单元格等于另一个单元格中的值,则更改为另一个单元格中的值 - If a cell in Column 7 equals the value in another cell change to the value in another cell 计算单元格是否等于另一个范围内的值,并且该单元格右边的单元格等于TRUE - Count if cell is equal to a value in another range and the cell to the right of that equals TRUE 从另一个工作表复制等于单元格值的单元格 - Copy cell that equals cell value from another worksheet 如果表单元格等于变量值 - If table cell equals variable value Excel 的多公式到 IF 等于从另一个单元格值复制 - Multi Formula for Excel to IF Equals copy from another cell value Excel - 如果另一个单元格 IF 等于 true,则使用一个值 - Excel - use one value if another cell IF equals true 如果单元格等于某个值,则VBA使该单元格成为下一个可用单元格 - VBA if cell equals certain value make that cell next available cell 查找列单元格是否等于另一个工作表中的另一个单元格 - Finding if a column cell equals another in a different sheet Excel - 条件格式以突出显示单元格值是否等于并且另一个单元格值早于日期 - Excel - Conditional Formatting to highlight if cell value equals and another cell value is before date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM