首页 > 解决方案 > 在特定单词处拆分字符串并创建新行

问题描述

我正在尝试在单词“material_cd”处拆分此字符串,并让它使用拆分字符串创建一个新行。

material_cd = 10798259 AND inputportcount 24 material_cd = 10798259 AND outputportcount 144 material_cd = 10798259 AND inputblockcount 1 material_cd = 10798259 AND outputblockcount 1 material_cd = 10798259 AND bv_type_name FDH material_cd = 10798259 AND manufacturer Corning material_cd = 10798259 AND partnumber N/A material_cd = 10798259 AND bv_status Preliminary设计材料 CD = 10798259 AND bv_tail_length 25

期望的结果:

material_cd = 10798259 AND inputportcount <> 24
material_cd = 10798259 AND outputportcount <> 144
material_cd = 10798259 AND inputblockcount <> 1
material_cd = 10798259 AND outputportcount <> 1

....等等

这可能吗?

标签: excelvbafunction

解决方案


像这样的东西,

Sub tt()

Dim s As String
Dim a() As String

s = "material_cd = 10798259 AND inputportcount  24 material_cd = 10798259 AND outputportcount  144 material_cd = 10798259 AND inputblockcount  1 material_cd = 10798259 AND outputblockcount  1 material_cd = 10798259 AND bv_type_name  FDH material_cd = 10798259 AND manufacturer  Corning material_cd = 10798259 AND partnumber  N/A material_cd = 10798259 AND bv_status  Preliminary Designed material CD = 10798259 AND bv_tail_length  25"
s = Replace(s, "material_cd", "*^*material_cd")
a = Split(s, "*^*")

Range("a1").Resize(UBound(a) - 1, 1).Value = Application.Transpose(a)

End Sub

推荐阅读