AA=A.B.C GE X N【O】U【V】【W】
与
AA=A.B.C GE X N[O]U[V][W]
显示效果不同。
英文左中括号([)前面和英文右中括号(])后面不加空格不会显示下面效果:
18.02.06 王维1003 大 曹操 [曹操2] A1 [A2] [A3]
只会显示成:
18.02.06 王维1003 大 曹操[曹操2]A1[A2][A3]
你的这一代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 25 And Target.Count = 1 Then
If Target.Value <> 0 Then
'AA=A.B.C GE X N【O】U【V】【W】
Target.Offset(, 2).Value = Target.Offset(, -24).Value & "." & Target.Offset(, -23).Value & "." & Target.Offset(, -22).Value _
& " " & Target.Offset(, -18).Value & Target.Offset(, -20).Value & " " & Target.Offset(, -1).Value & " " & Target.Offset(, -11).Value _
& "【" & Target.Offset(, -8).Value & Target.Offset(, -10).Value & "】 " & Target.Offset(, -4).Value & " 【" & Target.Offset(, -3).Value & "】 " & "【" & Target.Offset(, -2).Value & "】"
End If
End If
End Sub
(1)向AA列中输入数据会触发工作表的Change事件,造成重复运行此代码
(2)换个思路,向AA列输入公式的方法,代码如下。
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 25 And Target.Count = 1 And Target.Row > 1 Then
Range("AA" & Target.Row) = "=IF(RC[-2]=0,"""",CONCATENATE(TEXT(RC[-26]+ISODD(RC[-26]),""00""),""."",TEXT(RC[-25]+ISODD(RC[-25]),""00""),""."",TEXT(RC[-24]+ISODD(RC[-24]),""00""),"" "",RC[-20],RC[-22],"" "",RC[-3],"" "",RC[-13],IF(RC[-12]="""","""","" [""&RC[-12]&""] ""),RC[-6],"" "",IF(RC[-5]="""","""",""[""&RC[-5]&""] ""),IF(RC[-4]="""","""",""[""&RC[-4]&""]"")))"
End If
Application.EnableEvents = True
End Sub
上面粗体标注的代码不用担心写法,你录制宏——在AA2单元格输入公式:
=IF(Y2=0,"",CONCATENATE(
TEXT(A2+ISODD(A2),"00"),".",
TEXT(B2+ISODD(B2),"00"),".",
TEXT(C2+ISODD(C2),"00")," ",
G2,
E2," ",
X2," ",
N2,
IF(O2="",""," ["&O2&"] "),
U2," ",
IF(V2="","","["&V2&"] "),
IF(W2="","","["&W2&"]")))
然后停止录制宏就有了。
结果如下图所示: