![]() |
Wildcards
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 |
Wildcards
Try replacing
"8*****" with "8?????" -- Regards Juan Pablo González "properties" wrote in message ... 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 |
Wildcards
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 -- Regards Frank Kabel Frankfurt, Germany properties wrote: 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 |
Wildcards
That works great!
Thanks "Juan Pablo González" wrote in message ... Try replacing "8*****" with "8?????" -- Regards Juan Pablo González "properties" wrote in message ... 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 |
All times are GMT +1. The time now is 11:16 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com