Hi,
I am a beginner with VBA.
I want to write a code that can extract particluar cells from a named range.
For example I want to extract all the cells in column 1 say "Myrange" which contain Apples as a separate range i.e. desiredrange
MYRANGE DESIREDRANGE
1 7 Apples
2 11 Apples
3 15 Apples
4
5
6
7 Apples
8
9
10
11 Apples
12
13
14
15 Apples
I tried to writing this code but doesn't work. Please help me out. Thanks
Function extractarray(X As Range, Y As String) As Range
Dim Templist()
Dim I As Integer, J As Integer
J = 0
For I = 1 To X.Rows.Count
If Not InStr(X.Cells(I, 1), Y) = 0 Then
J = J + 1
End If
Next I
Numcount = J
K = 0
ReDim Templist(1 To Numcount)
For I = 1 To X.Rows.Count
If Not InStr(X.Cells(I, 1), Y) = 0 Then
K = 0 + K
Templist(K) = X.Value
End If
Next I
extractarray = Templist
End Function
Bookmarks