excel 单元格数据取前几位。。
怎样取以下数据,
CJ009-01外套 CJ009-01
红色衫
JJ001七分裤 JJ001
JC002(五分裤) JC002
JJ152 JJ152
SJ003-10 SJ003-10
KJ0034-01毛衣 KJ0034-01
A3分切
如上,EXCEL怎样自取前面所需的字符。。
[解决办法]
用
=IF(FIND(" ",A1,1) > 0, MID(A1,FIND(" ",A1,1),LEN(A1) -FIND(" ",A1,1)+1 ),"")
但对最下面哪行不行。
[解决办法]
实在不行写个VB小程序吧
[解决办法]
用公式可以的.
[解决办法]
如果楼主想要用VBA来实现,那么代码如下:
(刚刚试了下,结果与楼主的一致)
Sub GetCode() Dim FinalRow As Long, i As Long, j As Long, Length As Long Dim Sh1 As Worksheet Set Sh1 = Worksheets("表1") With Sh1 FinalRow = .Cells(65535, 1).End(xlUp).Row For i = 1 To FinalRow Length = Len(.Cells(i, 1)) If Length > 0 Then For j = 1 To Length If Asc(Mid$(.Cells(i, 1), j, 1)) > 127 Or Asc(Mid$(.Cells(i, 1), j, 1)) < 42 Then If j > 1 Then .Cells(i, 2) = Trim$(Left$(.Cells(i, 1), j - 1)) End If Exit For End If If j = Length And Asc(Mid$(.Cells(i, 1), j, 1)) < 127 And Asc(Mid$(.Cells(i, 1), j, 1)) > 42 Then .Cells(i, 2) = Trim$(.Cells(i, 1)) End If Next j End If Next i End WithEnd Sub
[解决办法]