View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default MID and FIND function in vba

Oops.., mis-located row counter. Fixed here...

Dim sState$, vData, vTmp, n&, k&

'Load the state - city list into vData,
'Then split each element using the " - " as delimeter
' and dump the 2nd element into colD if match...

k = 2 '//1st row of data
With Sheets("Sheet1")
sState = .Cells(1, 8).Value
For n = 1 to UBound(vData)
vTmp = Split(vData(n, 1), " - ")(1)
If vTmp(0) = sState Then .Cells(k, 4) = vTmp(1)
k = k + 1
Next 'n
End With

Optionally, if data starts in row2...
Dim sState$, vData, vTmp, n&
With Sheets("Sheet1")
sState = .Cells(1, 8).Value
For n = 1 to UBound(vData)
vTmp = Split(vData(n, 1), " - ")(1)
If vTmp(0) = sState Then .Cells(n + 1, 4) = vTmp(1)
Next 'n
End With

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus