My last problem.
Is there away to use a variable like i and replace
Set foundCell = .Find(What:=p1 with pi
and
Destination:=Worksheets("Sheet2").Range("A2") with ("Ai")
and loop it so pi/Ai will cycle from p1 to p40?
This would reduce my code to a very small amount.
Otherwise, I would have to reproduce the code 40 times!
I tried the variable i with a loop and it failed.
All i need now is to cycle from 1 to 40.
Sub Macro1()
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\user\Desktop\data.txt",
Destination:=Range("A1" _
))
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1)
.Refresh BackgroundQuery:=False
End With
Dim FoundCell
'Update this List of numbers as needed.
p1 = "o305"
p2 = "o983"
p3 = "o606"
Upto p40
With ActiveSheet.Range("a:a")
Set FoundCell = .Find(What:=p1, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
'can't find the number
Else
FoundCell.EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A2")
End If
End With
End Sub