Wildcards

P

properties

In my if statement I want to select only cells that start with "8" and are
six characters long.
The wild card does not work. How do I limit the cells selected to match the
criteria above?

T.I.A.



Sub PO_Test()
Dim i As Long
Dim LastRow As Long
Dim strPo As String

LastRow = Range("A2000").End(xlUp).Row

For i = LastRow To 1 Step -1
If Range("A" & i) Like "8*****" Then
strPo = Range("A" & i).Value
ElseIf Range("D" & i) Like "8*****" Then
strPo = Range("D" & i).Value
End If
Range("H" & i).Value = strPo
Next 'i

End Sub
 
F

Frank Kabel

Hi
try the following:
Sub PO_Test()
Dim i As Long
Dim LastRow As Long
Dim strPo As String

LastRow = Range("A2000").End(xlUp).Row

For i = LastRow To 1 Step -1
if Len(cells(i,"A").value)=6 and
Left(cells(i,"A").value,1)="8" then
strPo = cells(i,"A").Value
elseif Len(cells(i,"D").value)=6 and
Left(cells(i,"D").value,1)="8" then
strPo = cells(i,"D").Value
end if
cells(i,"H").value = strPo
next
End Sub
 
Top