英文:
Creating new column based on containing letter below
问题
我有一个数据集,看起来像下面这样:
Nickel 10
Nickel U
Nickel 10
Nickel U
Nickel 10
Nickel U
Nickel 1.4
Nickel J
Nickel 10
Nickel U
Nickel 10
Nickel U
Nickel 10
Nickel U
Sodium 8.1
Sodium 7.4
Sodium 6.2
Sodium 7.6
Sodium 7.9
Sodium 6.9
Sodium 7.8
Sodium 8.9
Sodium 9
Sodium 7.9
Sodium 7
Sodium R
Sodium 8.4
Sodium 7.7
一些行下面有与上面的数字对应的字符。例如:Nickel 10 U。我想要在有字符在下面的情况下添加另一列用于该字符。棘手的部分是,有些数值不对应字符(如果下面没有字符),这些数值需要保持为空白。
我可以创建一个代码来询问:如果有字符在数值下方,那么在相邻的列中添加字符。如果数值下面没有字符,将相邻列保留为空白。
英文:
I have a dataset that looks like the following:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
Nickel 10
Nickel U
Nickel 10
Nickel U
Nickel 10
Nickel U
Nickel 1.4
Nickel J
Nickel 10
Nickel U
Nickel 10
Nickel U
Nickel 10
Nickel U
Sodium 8.1
Sodium 7.4
Sodium 6.2
Sodium 7.6
Sodium 7.9
Sodium 6.9
Sodium 7.8
Sodium 8.9
Sodium 9
Sodium 7.9
Sodium 7
Sodium R
Sodium 8.4
Sodium 7.7
<!-- end snippet -->
Some rows have characters below it that correspond to the number above. Example: Nickel 10 U. I would like to add another column for the character IF a number has that character below it. The tricky part is, some are values do not correspond to a character (if there is not a character below) and those will need to remain blank.
Can I create a code that asks: if there is a character below a value, then add character in adjacent column. If there is no character below a value, leave the column adjacent blank.
答案1
得分: 0
=IF(ISTEXT(B2),B2,"")
这段代码检查B列下面的单元格。如果它是文本,就返回下面单元格中的文字。如果不是文本,就返回空白。你可以拖动这个公式来覆盖所有你的数据。
英文:
=IF(ISTEXT(B2),B2,"")
This checks the cell beneath in column B. If it is text then it returns the letter in the cell beneath. If it is not text then it returns blank. You can drag the formula down to cover all of your data.
答案2
得分: 0
数据移动
单个单元格(向下复制)
=IF(AND(ISNUMBER(B1),ISTEXT(B2)),B2,"")
数组公式(Microsoft 365中的溢出)
=IF(ISNUMBER(B1:B13)*ISTEXT(B2:B14),B2:B14,"")
吹毛求疵
- 两个解决方案实际上都不准确,因为它们包括标题(
B1
)。 - 将范围向下移动一行同样会包括数据下面的单元格(
B15
)。 - 在Microsoft 365中,您可以通过使用
VSTACK
和DROP
获取向上移动的数据版本,然后可以将值进行逐一比较(参见E:F
列)。
=LET(d,B2:B14,
s,VSTACK(DROP(d,1),""),
IF(ISNUMBER(d)*ISTEXT(s),s,""))
英文:
Shifting Data
Single Cell (Copy Down)
=IF(AND(ISNUMBER(B1),ISTEXT(B2)),B2,"")
Array Formula (Spills in Microsoft 365)
=IF(ISNUMBER(B1:B13)*ISTEXT(B2:B14),B2:B14,"")
Nitpicking
- Both solutions are actually inaccurate since they include the header (
B1
). - Shifting the ranges one row down will similarly include a cell below the data (
B15
). - In Microsoft 365, you can work around this by getting a version of the data shifted up by using
VSTACK
andDROP
. Then you can compare the values side-by-side so to speak (see columnsE:F
).
=LET(d,B2:B14,
s,VSTACK(DROP(d,1),""),
IF(ISNUMBER(d)*ISTEXT(s),s,""))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论