简体   繁体   English

根据单元格长度设置单元格值

[英]Set cell value using based on cell length

I have this kind of product id in column D:我在 D 列中有这种产品 ID:

  • 1942-PS-M-01 1942-PS-M-01
  • 1942-PS-M-233 1942-PS-M-233
  • 1942-PM-25 1942-PM-25
  • 1942-PL-200 1942-PL-200

I want to set the value in column G Using the last 2/3 number in the product id value.我想使用产品 ID 值中的最后 2/3 数字设置 G 列中的值。

I tried to use formula such =MID([Product_ID],11,3) and =MID([Sample_ID],10,3), but none of this id efficient and I have to enter the formula 1 by 1 since the id is doest not have same length.我尝试使用诸如 =MID([Product_ID],11,3) 和 =MID([Sample_ID],10,3) 之类的公式,但是这个 id 没有一个有效,我必须按 1 输入公式,因为 id 是没有相同的长度。

Is there any way to do so by using vba?有没有办法通过使用vba来做到这一点? because I have almost 20k rows of data因为我有将近 20k 行数据

I have an idea like using if (len([Product_ID])<13 then =MID([Product_ID],11,3) or if (len([Product_ID])<12 then =MID([Product_ID],10,3) but doest not know how to implement this in vba我有一个想法,比如使用 if (len([Product_ID])<13 then =MID([Product_ID],11,3) 或 if (len([Product_ID])<12 then =MID([Product_ID],10,3) ) 但不知道如何在 vba 中实现

Use the following formula:使用以下公式:

=MID(D1,FIND("-",D1,FIND("-",D1,FIND("-",D1)+1)+1)+1,LEN(D1))

This will work as long as there are consistently three dashes in your product id.只要您的产品 ID 中始终存在三个破折号,这就会起作用。 It looks for the position of the first dash, then the second, then the third and extracts the rest of the string after the third dash.它查找第一个破折号的位置,然后是第二个,然后是第三个,并在第三个破折号之后提取字符串的其余部分。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM