LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default MID and FIND function in vba

With a list of state/city in column A.

Wyoming - Greybull
Indiana - South Bend
Illinois - Itasca
Texas - Mineral Wells
Wyoming - Powell
Wyoming - Cody
Texas - Houston
Illinois - Fox Valley
Texas - Waco

I want the city returned to column D, where aState is a selection in H1 DV drop down.

The code errors on the word FIND in the MID function.
The mid function works on the sheet as a formula. (with H1 cell ref, not rngC)

Sub my_Instr_Copy()
Dim LRow As Long
Dim rngC As Range
Dim aState As String, aCity As String


With Sheets("Sheet1")

LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
aCity = .Cells(1, 8)

For Each rngC In .Range("A2:A" & LRow)
Set aCity = Mid(rngC, Find("- ", rngC) + 2, 99)

If InStr(rngC, aState) 0 Then
Sheets("Sheet1").Range("D" & Rows.Count).End(xlUp)(2) = aCity
End If

Next

End With
End Sub

Thanks,
Howard
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If find function to not find anything Carlos Excel Programming 4 February 14th 08 09:25 AM
Find function using chr gazza67[_2_] Excel Programming 1 September 13th 07 08:42 AM
Need to find a function. MikeCampbell Excel Worksheet Functions 2 January 29th 07 01:40 AM
Find Function kiza[_4_] Excel Programming 2 June 11th 04 02:49 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM


All times are GMT +1. The time now is 03:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"