MID and FIND function in vba
With my_Instr_Copy() code it errors wanting an Object or Variable set, tried many different sets, but don't see it.
With my_Instr_Copy_1() code works to list all cities in column D, but the requirement is for only the cities of the state shown in cell H1's DV drop down.
Howard
Sub my_Instr_Copy()
Dim rngC As Range
Dim aState As Range
Dim aCity As Range
aState = Cells(1, 8)
Set aCity = Mid(aState, InStr(aState, " - ") + 3, 99)
With Sheets("Sheet1")
For Each rngC In .Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
If InStr(rngC, aState) 0 Then
Sheets("Sheet1").Range("D" & Rows.Count).End(xlUp)(2) = aCity
End If
Next
End With
End Sub
Sub my_Instr_Copy_1()
Dim vData As Variant, n&, k&
vData = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
k = 2
With Sheets("Sheet1")
For n = 1 To UBound(vData)
.Cells(k, 4) = Split(vData(n, 1), " - ")(1): k = k + 1
Next 'n
End With
End Sub
|